Ask A Question
0

Concat PChar with string in Delphi

Asked by TheDude on 11/19/2012 at 8:09 PM

I need to construct a string and send it via PostMessage, ie.

FileName := String_1 + String_2 + String_3;
PostMessage(FWndHandle, WM_BLA_BLA, NotifyData^.Action, LParam(FileName));

but something isn't working. Plus, FileName is a PChar. The code looks like this:

var
   FileName : PChar;
   Directory_Str : String;
   AnotherString : String;
begin
    // Get memory for filename and fill it with data
    GetMem(FileName, NotifyData^.FileNameLength + SizeOf(WideChar));
    Move(NotifyData^.FileName, Pointer(FileName)^, NotifyData^.FileNameLength);
    PWord(Cardinal(FileName) + NotifyData^.FileNameLength)^ := 0;

    // TODO: Contact string before sending message
    // FileName := AnotherString + Directory_Str + FileName;

    PostMessage(FWndHandle, WM_BLA_BLA, NotifyData^.Action, LParam(FileName));

    ...
end;

Now I need to do contact another string to the variable FileName before calling PostMessage, ie.

FileName := AnotherString + Directory_Str + FileName;
PostMessage(FWndHandle, WM_BLA_BLA, NotifyData^.Action, LParam(FileName));

This would work if FileName was a string, which is not the case here.

Anyone knows how to do that with PChar? I tried these methods, works sometimes but always something breaks at the end:

StrPCopy(FileName, FDirectory + String(FileName));

OR

FileName := PChar(AnotherString + Directory_Str + FileName);
View Full Answer On Stackoverflow

Responses

No responses yet. Be the first one!

    [Some content on this page is from Stackoverflow]