![]() |
Typ einzelner Array of const-Elemente
Ich möchte
![]() Wie genau bekomme ich denn den Typ der einzelnen Parameter raus? Ich weiß wie ich einzelne davon typisiere, aber nicht, wie ich herausbekommen kann von was für einem typ es ist. |
Re: Typ einzelner Array of const-Elemente
Delphi-Quellcode:
(Ausschnitt aus einer Funktion (die wahrscheinlich in diesem Ausscheitt recht sinnlos geworden ist))
function fstr(z:variant):string;
begin if (TVarData(z).VType = varinteger) or(TVarData(z).VType = varbyte) or(TVarData(z).VType = varword) or(TVarData(z).VType = varint64) then str(z:0:0,result) else str(z,result); end; Mit nem array of const dürfte es genauso funktionieren. |
Re: Typ einzelner Array of const-Elemente
Leider nicht :cry:
So versuche ich es:
Delphi-Quellcode:
procedure Test(a: Array of Const);
var i: Integer; begin for i := 0 to high(a) do begin if (TVarData(a[i]).VType=varinteger) or(TVarData(a[i]).VType = varbyte) or(TVarData(a[i]).VType = varword) or(TVarData(a[i]).VType = varint64) then ShowMessage(IntToStr(a[i]); end; end; |
Re: Typ einzelner Array of const-Elemente
Natürlich geht das nicht, ein array of const ist schließlich kein array of Variant.
Ich denke mal, du kannst nur die Größe der einzelnen Array-Elemente feststellen und auf sie zugreifen. |
Re: Typ einzelner Array of const-Elemente
Hi,
nee, so nicht, ist ja kein Variant array aber auf der ![]() How to use an array of const
Delphi-Quellcode:
Gruss
procedure AddStuff( Const A: Array of Const );
Var i: Integer; Begin For i:= Low(A) to High(A) Do With A[i] Do Case VType of vtExtended: Begin { add real number, all real formats are converted to extended automatically } End; vtInteger: Begin { add integer number, all integer formats are converted to LongInt automatically } End; vtObject: Begin If VObject Is DArray Then With DArray( VObject ) Do Begin { add array of doubles } End Else If VObject Is IArray Then With IArray( VObject ) Do Begin { add array of integers } End; End; End; { Case } End; { AddStuff } |
Re: Typ einzelner Array of const-Elemente
Zitat:
€dit: Ich mach es jetzt mit Variants, danke dir ;) |
Re: Typ einzelner Array of const-Elemente
Du nimmst statt TVardata TVarRec.
etwa so:
Delphi-Quellcode:
Edit:
for i:=0 to high(a) do begin
if (TVarRec(a[i]).VType = vtinteger) then memo1.lines.Add(inttostr(TVarRec(a[i]).VInteger)) end; Zitat:
|
Re: Typ einzelner Array of const-Elemente
Habe dein Edit erst jetzt gesehen, so klappt es auch wunderbar, danke!
|
Re: Typ einzelner Array of const-Elemente
Zitat:
Übrigens: Manchmal musst du schauen welchen Typ du überhaupt übergibst. Grade bei strings gibt es ja für vtype mehrere Varianten. Dann lass dir einfach mal testweise vtype ausgeben und schau, welchen Typ du übergeben hast. |
Re: Typ einzelner Array of const-Elemente
Ich hab mir vor einiger Weile mal eine Funktion geschrieben, die ein Array of Const "lesbar" macht.
Evtl. hilft dir das :)
Delphi-Quellcode:
class function TCODDBHelperClass.ArrayToString(Arr: Array of Const): String;
var Loop : Integer; Value : TVarRec; begin Result := '['; for Loop := 1 to Length(Arr) do begin Value := Arr[Loop - 1]; case Value.VType of vtInteger : Result := Result + IntToStr(Value.VInteger); vtBoolean : Result := Result + BoolToStr(Value.VBoolean); vtChar : Result := Result + Value.VChar; vtExtended : Result := Result + FloatToStr(Value.VExtended^); // '_EXTENDED_'; vtString : Result := Result + '''' + Value.VString^ + ''''; vtPointer : Result := Result + Format('%p', [Value.VPointer]); vtPChar : Result := Result + '''' + Value.VPChar + ''''; vtObject : Result := Result + '_OBJECT_'; vtAnsiString : Result := Result + '''' + String(Value.VAnsiString) + ''''; vtCurrency : Result := Result + CurrToStr(Value.VCurrency^); //'_CURRENCY_'; vtVariant : Result := Result + Value.VVariant^; vtWideString : Result := Result + '''' + WideString(Value.VWideString) + ''''; vtInt64 : Result := Result + IntToStr(Int64(Value.VInt64)); else Result := Result + '_UNKNOWN_'; end; if (Loop < Length(Arr)) then Result := Result + ', '; end; Result := Result + ']'; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz