Hello all, I'm perplexed here really. This is in Delphi 7
I Have a snippet

var
U:string;
UserPath:string;
begin
U := GetCurrentUserName;

My get Username works fine calling on a function I wrote however when I am attempting to insert that username in a directory path it wont place the ending???

procedure TSpUser.SpeedButton7Click(Sender: TObject);
var
U:string;
UserPath:string;
begin
U := GetCurrentUserName;
UserPath := 'C:\Documents and Settings\' + (U) + '\Local Settings\Temp\';
PlaySound('type', hInstance, SND_RESOURCE or SND_SYNC);
Label9.Caption:=UserPath;
end;

What I get is C:\Documents and Settings\users name but the \Local Settings\Temp\ just wont show????
Am I missing something really simple here?

Thanks if you can help

The code looks fine to me.

Are you sure there isn't an extraneous #0 at the end of U?

The code looks fine to me.

Are you sure there isn't an extraneous #0 at the end of U?

Hey Duoas. Thank for reading.
No anything extra. This little problem is sending me nannas lol.
I've even broken the line into three seperate String and done an individual read on all and get exactly what is needed but when I attempt to join it all together ....fizzzzle

try to add :
ShowMessage('-'+U+'-');
Exit;

After the "U := GetCurrentUserName;" line.

i use that way to debug sometimes.
Using a BreakPoint (F5) wont show you if you have a Space or a CRLF.
if you do have that, then maybe you can try :
UserPath := 'C:\Documents and Settings\' + Trim(U) + '\Local Settings\Temp\';

if you do have a Space or a CRLF in the U, then i would check that GetCurrentUserName function if i were you.

i use the Trim function a lot, just to be on the safe side.

good luck :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.