Autor Beitrag
Mike_C
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Di 12.08.03 09:08 
Hi

wie kann ich eine Paradox Datenbank zur Laufzeit generieren?

ich habe zwar ein stück code zu den thema, aber das scheint unter WinXP nicht zu funktionieren.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function TForm1.CreateDB(db,table: string):boolean;
var t: ttable;
begin
  result := false;
  CreateDirectory (Pchar (db), nil);  //unterverzeichnis anlegen
  t := ttable.Create(self);
  t.databasename := db;
  t.tablename := table;
  t.tabletype := ttparadox;
  //here go fielddefs
  //... 
  //here go indexdefs
  //...
  try
    t.createtable;
  except
    result := false;
    exit;
  end;
  result := true; 
end;


mit diesem code kann ich keine db erstellen. es heißt immer "Datei oder Verzeichnis existiert nicht". Wenn ich eine leere paradox-db in ein subdir stelle, wird das file gefunden und gelöscht statt überschrieben zu werden.

wie kann ich das ändern?

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Di 12.08.03 10:02 
Du erstellst mit dem Befehl ja auch keine Tabelle, sondern eine TTable-Komponente. Die Tabelle an sich wird so erstellt:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
{ Evtl. vorhandene Tabelle nicht überschreiben }

if not Table1.Exists then begin

  with Table1 do begin

  { Die Table-Komponente darf nicht aktiv sein }
  Active := False;
  { Zuerst den Tabellentyp beschreiben und die Tabelle benennen }
  DatabaseName := 'DBDEMOS';
  TableType := ttParadox;
  TableName := 'CustInfo';

  { Dann die Felder in der Tabelle beschreiben }
  with FieldDefs do begin
    Clear;
      with AddFieldDef do begin
        Name := 'Field1';
        DataType := ftInteger;
        Required := True;
      end;

      with AddFieldDef do begin
        Name := 'Field2';
        DataType := ftString;
        Size := 30;
      end;

    end;

  { Dann alle Indizes beschreiben }
  with IndexDefs do begin
    Clear;
    { Der erste Index hat keinen Namen, denn er ist ein }
    { primärer Paradox-Schlüssel }
      with AddIndexDef do begin
        Name := '';
        Fields := 'Field1';
        Options := [ixPrimary];
      end;
      with AddIndexDef do begin
        Name := 'Fld2Indx';
        Fields := 'Field2';
        Options := [ixCaseInsensitive];

      end;
    end;
  { CreateTable-Methode zu Erzeugen der Tabelle aufrufen }
  CreateTable;
  end;
end;

Dieses Beispiel ist 1:1 aus der Delphi-Hilfe kopiert aus dem Befehl "CreateTable" der TTable-Komponente.

Viele Grüße,
Matthias

_________________
Ha! Es compiliert! Wir können ausliefern!
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Di 12.08.03 10:16 
thx,

hab vergessen die hilfe zu konsultieren ;-)

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Di 12.08.03 10:31 
mhh das bingt mich noch nicht wirklich weiter...

also ich möchte folgendes erreichen (hab ich vorhion vergessen zu erwähnen, sorry...)

ich habe eine applikation, die mit datenbanken arbeiten soll. diese werden in einem unterverzeichn is "DB" gespeichert. die applikation soll nun prüfen, ob eine bestimmte datenbank (nennen wir sie test.db) existiert. wenn nicht, soll TEST.DB erstellt werden.

wie bekomme ich sowas hin?

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?
Mike_C Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 207

Win XP
D7 Enterprise
BeitragVerfasst: Di 12.08.03 10:33 
ok, ich hab das problem gelöst:

die eigenschaft DATABASE von TTable-objekt muss auf das unterverzeichnis verweisen

_________________
Life is, what some people call a mystery. To me life's just a lesson, you're learning when you're through. So why do we try to understand?