Autor Beitrag
kiwicht
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Mi 26.05.04 11:04 
Hallo,

ich krieg zwar so:

ausblenden Delphi-Quelltext
1:
IntToStr(Ord(query.FieldDefs[i].DataType));					


raus, welchen Datentyp ein Feld einer DB enthält, aber leider gibt dieses Codefetzen nur eine Zahl zurück... wie bekomme ich jetzt den tatsächlichen Typen raus, als CHAR, INTEGER etc. pp?

Hintergrund, ich baue gerade ein Tool welches DBF-DB´s auf einem MySQL-Server einspielt, und will das möglichst dynamisch machen.
Heisst also das alle Felder und deren Definition irgendwie zur Laufzeit herausbekommen werden müssen.. aber leider gibts in Delphi keine direkte Eigenschaft um das alles ohne weiteres auszulesen.

Danke schonma
mfg
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 26.05.04 11:11 
Lass das Ord() doch einfach weg ... :wink:


Danach kannst du bequem auf die in der Delphi-Hilfe unter TFieldType beschriebenen Datentypen a la ftString, ftInteger usw. abprüfen, z.B. per case-Anweisung.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
kiwicht Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Mi 26.05.04 13:14 
Danke...

1 steht also für Zeichen
6 für Zahl
9 für Datum...

In der Hilfe hab ich dazu leider nichts gefunden... und mit dem Ord weglassen war keine so gute Idee, da gabs erstmal kleinen Fehler...egal :)

Und das nächste Problem:

Die Länge :/

Angeblich soll das ja die Eigenschaft "DataSize" das Problem lösen können... tut´s aber nicht, weil diese Eigenschaft gibts garnicht in der Query Komponente oO

Danke im Voraus :)

mfg
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 26.05.04 14:13 
So eine Funktion hatte ich mir mal dazu gebaut.
Vielleicht hilft es ja wenn du es dir mal ansiehst.
Sie löst gleich beide Probleme auf einmal. 8)

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:
function FieldtypeToString(Fld: TField; ShowSize: Boolean): String;
begin
 Case Fld.DataType of
   ftString       : Result := 'CHAR';
   ftSmallint     : Result := 'SMALLINT';
   ftInteger      : Result := 'INTEGER';
   ftWord         : Result := 'WORD';
   ftBoolean      : Result := 'BOOLEAN';
   ftFloat        : Result := 'FLOAT';
   ftCurrency     : Result := 'CURRENCY';
   ftBCD          : Result := 'BCD';
   ftDate         : Result := 'DATE';
   ftTime         : Result := 'TIME';
   ftDateTime     : Result := 'DATETIME';
   ftBytes        : Result := 'BYTES';
   ftVarBytes     : Result := 'VARBYTES';
   ftAutoInc      : Result := 'AUTOINC';
   ftBlob         : Result := 'BLOB';
   ftMemo         : Result := 'MEMO';
   ftGraphic      : Result := 'GRAPHIC';
   ftFmtMemo      : Result := 'FORMATTED MEMO';
   ftParadoxOle   : Result := 'PARADOX OLE';
   ftDBaseOle     : Result := 'DBASE OLE';
   ftTypedBinary  : Result := 'TYPED BINARY';
   ftCursor       : Result := 'CURSOR (ORACLE)';
   ftFixedChar    : Result := 'FIXED CHAR';
   ftWideString   : Result := 'WIDE STRING';
   ftLargeInt     : Result := 'LARGEINT';
   ftADT          : Result := 'ABSTRACT DATA TYPE';
   ftArray        : Result := 'ARRAY';
   ftReference    : Result := 'REFERENCE';
   ftDataSet      : Result := 'DATA SET';
   ftOraBlob      : Result := 'ORACLE 8 - BLOB';
   ftOraClob      : Result := 'ORACLE 8 - CLOB';
   ftVariant      : Result := 'VARIANT';
   ftInterface    : Result := 'INTERFACE';
   ftIDispatch    : Result := 'DISPATCH - REFERENCE';
   ftGuid         : Result := 'GUID';
  else Result := 'UNKNOWN DATA TYPE';
 end;
 If ShowSize and (Fld.Size > 0)
  then Result := Result + ' (' + IntToStr(Fld.Size) + ')';
end;


Ich habe hier die von Delphi vordefinierten Bezeichner verwendet. Diese hättest du eigentlich in der Hilfe unter TFieldType finden müssen.

An die Grösse kommt man, wie du siehst, über die Eigenschaft Size von TField.


Hoffe, dir damit geholfen zu haben.

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!


Zuletzt bearbeitet von FaTaLGuiLLoTiNe am Mi 26.05.04 14:14, insgesamt 1-mal bearbeitet
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 26.05.04 14:13 
Hallo,

den Felddatentyp kannst Du mit folgender Routine ermitteln (uses DB nicht vergessen):
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:
function GetFieldType(aFieldType:TFieldType):String;
begin
  case aFieldType of
    ftUnknown    :Result:='Unknown or undetermined';
    ftString     :Result:='Character or string field';
    ftSmallint   :Result:='16-bit integer field';
    ftInteger    :Result:='32-bit integer field';
    ftWord       :Result:='16-bit unsigned integer field';
    ftBoolean    :Result:='Boolean field';
    ftFloat      :Result:='Floating-point numeric field';
    ftCurrency   :Result:='Money field';
    ftBCD       :Result:='Binary-Coded Decimal field';
    ftDate       :Result:='Date field';
    ftTime       :Result:='Time field';
    ftDateTime   :Result:='Date and time field';
    ftBytes      :Result:='Fixed number of bytes (binary storage)';
    ftVarBytes   :Result:='Variable number of bytes (binary storage)';
    ftAutoInc    :Result:='Auto-incrementing 32-bit integer counter field';
    ftBlob       :Result:='Binary Large OBject field';
    ftMemo       :Result:='Text memo field';
    ftGraphic    :Result:='Bitmap field';
    ftFmtMemo    :Result:='Formatted text memo field';
    ftParadoxOle :Result:='Paradox OLE field';
    ftDBaseOle   :Result:='dBASE OLE field';
    ftTypedBinary:Result:='Typed binary field';
    ftCursor     :Result:='Output cursor from an Oracle stored procedure (TParam only)';
    ftFixedChar  :Result:='Fixed character field';
    ftWideString :Result:='Wide string field';
    ftLargeInt   :Result:='Large integer field';
    ftADT       :Result:='Abstract Data Type field';
    ftArray      :Result:='Array field';
    ftReference  :Result:='REF field';
    ftDataSet    :Result:='DataSet field';
    ftOraBlob    :Result:='BLOB fields in Oracle 8 tables';
    ftOraClob    :Result:='CLOB fields in Oracle 8 tables';
    ftVariant    :Result:='Data of unknown or undetermined type';
    ftInterface  :Result:='References to interfaces (IUnknown)';
    ftIDispatch  :Result:='References to IDispatch interfaces';
    ftGuid       :Result:='globally unique identifier (GUID) values';
  end; // case
end; // GetFieldType


Folgendes Beispiel füllt eine ListView (mit 3 Spalten: Feldname | FeldTyp | Feldgröße) mit den entsprechenden Infos:
ausblenden 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:
resourcestring
  rsFmtByte='%d Byte';

procedure ViewDataset(aLV:TListView; aDS:TDataSet);
var i:Integer;
begin
  with aDS do
  begin
    with aLV do
    begin
      Items.BeginUpdate;
      try
        Items.Clear;
        for i:=0 to FieldCount-1 do
        begin
          with Items.Add do
          begin
            Caption:=Fields[i].DisplayName;
            SubItems.Add(GetFieldType(Fields[i].DataType));
            SubItems.Add(Format(rsFmtByte, [Fields[i].DataSize]));
            ImageIndex:=0;
          end; // with
        end; // for i
      finally
        Items.EndUpdate;
      end; // try
    end; // with
  end; // with
end; // ViewDataset

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mi 26.05.04 14:15 
@smiegel: Meep, meep 8)

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
kiwicht Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Do 27.05.04 20:15 
:shock:

:D

Danke euch beiden, hilft schonmal n gutes Stück weiter :)

mfg