What is the difference between this: Get link Facebook X Pinterest Email Other Apps - May 14, 2013 What is the difference between this:IntToStr(10)string(10)? Get link Facebook X Pinterest Email Other Apps Comments Nándor KissMay 14, 2013 at 5:56 AMIntToStr(10) -> '10'string(10) -> E2089 Invalid typecastReplyDeleteRepliesReplyIngo WagnerMay 14, 2013 at 5:59 AMNándor Kiss string(10) works here, I am asking because I just saw it written in some code I am fixing at work. It's actually string(i + 1), but you get the point. Do you know any way it could work?ReplyDeleteRepliesReplyNándor KissMay 14, 2013 at 6:03 AMIn XE it does not work:var S: string;begin S := string(16); // <-- [DCC Error] xxx.dpr(xx): E2089 Invalid typecastend.What is the Delphi version You're using?ReplyDeleteRepliesReplyNándor KissMay 14, 2013 at 6:04 AMOk i got the point.... it's some hack to manuallty set the pointer of a string... bad way...ReplyDeleteRepliesReplyNándor KissMay 14, 2013 at 6:05 AMvar I: Integer; S: string;begin I := 16; S := string(I + 1); <- AV hereend.ReplyDeleteRepliesReplyIngo WagnerMay 14, 2013 at 6:06 AMNvm, I debugged it and there is an empty try except hiding the raise, it's like this:try doSomething;exceptend;procedure doSomething;begin [code...] string(i+1); [...code]end;Great way to break things...ReplyDeleteRepliesReplyStefan GlienkeMay 14, 2013 at 6:10 AMThat reminds me of storing strings in the TComponent.Tag property....ReplyDeleteRepliesReplyMartin WienoldMay 14, 2013 at 6:39 AMStefan Glienke x.Tag := NativeInt(PChar('some string'))? ;)ReplyDeleteRepliesReplyIngo WagnerMay 14, 2013 at 6:42 AMMartin Wienold Why?ReplyDeleteRepliesReplyMartin WienoldMay 14, 2013 at 10:38 PMIngo Wagner Jr.That is what we (Stefan Glienke and myself) have found in our source code .. well not exactly this, but you get the idea.ReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment
IntToStr(10) -> '10'
ReplyDeletestring(10) -> E2089 Invalid typecast
Nándor Kiss string(10) works here, I am asking because I just saw it written in some code I am fixing at work. It's actually string(i + 1), but you get the point. Do you know any way it could work?
ReplyDeleteIn XE it does not work:
ReplyDeletevar
S: string;
begin
S := string(16); // <-- [DCC Error] xxx.dpr(xx): E2089 Invalid typecast
end.
What is the Delphi version You're using?
Ok i got the point.... it's some hack to manuallty set the pointer of a string... bad way...
ReplyDeletevar
ReplyDeleteI: Integer;
S: string;
begin
I := 16;
S := string(I + 1); <- AV here
end.
Nvm, I debugged it and there is an empty try except hiding the raise, it's like this:
ReplyDeletetry
doSomething;
except
end;
procedure doSomething;
begin
[code...]
string(i+1);
[...code]
end;
Great way to break things...
That reminds me of storing strings in the TComponent.Tag property....
ReplyDeleteStefan Glienke x.Tag := NativeInt(PChar('some string'))? ;)
ReplyDeleteMartin Wienold Why?
ReplyDeleteIngo Wagner Jr.
ReplyDeleteThat is what we (Stefan Glienke and myself) have found in our source code .. well not exactly this, but you get the idea.