Autor Beitrag
BigAl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 31

XP, Vista, 7, 2000+ Server
RAD Studio XE / XE2 EP/Prof., C#, MSSQL, HTML, PHP, Step 7...
BeitragVerfasst: So 22.05.11 22:26 
Hallo zusammen,

ich versuche gerade Varianten an System.Format zu übergeben. Teilweise gehts, teilweise nicht. Die Hilfe gibt da leider auch nicht wirklich viel her. Also z.B.:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  S: Variant; // string;
  I: Variant; // Integer;
begin
  S := 'Hallo';
  I := 123;
  Format('%s', [S]); // geht
  Format('%i', [I]); // wirft eine Exception (Typ nicht kompatibel)
end;


Ist nur ein Beispiel zum Verständnis. In meinem Code ist das etwas komplexer.

Hat irgendwer eine Idee wie man das umgehen könnte?

Alex
mandras
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 434
Erhaltene Danke: 107

Win 10
Delphi 6 Prof, Delphi 10.4 Prof
BeitragVerfasst: So 22.05.11 22:35 
Habs nicht ausprobiert, aber:

stimmt das im Quelltext ('%i') ?

um Integer auszugeben muß %d verwendet werden.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 22.05.11 22:48 
user profile iconmandras hat folgendes geschrieben Zum zitierten Posting springen:
um Integer auszugeben muß %d verwendet werden.
Richtig, aber das war vermutlich nur ein Tippfehler. ;-)

Damit die Umwandlung klappt, musst du den Typ angeben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  S: Variant; // string;
  I: Variant; // Integer;
begin
  S := 'Hallo';
  I := LongInt(123);
  Format('%s', [S]);
  Format('%i', [LongInt(I)]);
end;
BigAl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 31

XP, Vista, 7, 2000+ Server
RAD Studio XE / XE2 EP/Prof., C#, MSSQL, HTML, PHP, Step 7...
BeitragVerfasst: Mo 23.05.11 06:18 
Hi,

das mit dem %i war natürlich ein Tippfehler. Aber es geht natürlich trotzdem nicht.

Ich habe mittlerweile auch einen Artikel bei Embarcadero über das Thema gefunden. In einem Forum. Es scheint noch mehr Leute zu geben, die das gerne hätten :-). Wäre scheinbar auch keine großé Sache das zu implementieren. Hab's mir aber noch nicht genauer angeschaut...

Alex