Forum > General
Get username and hostname from Windows ?
(1/1)
seba22:
Welcome,
How can i run following functions under Lazarus (Win32)
--- Code: ---function GetComputerNetName: string;
var
buffer: array[0..255] of char;
size: dword;
begin
size := 256;
if GetComputerName(buffer, size) then
Result := buffer
else
Result := ''
end;
Function GetUserFromWindows: string;
Var
UserName : string;
UserNameLen : Dword;
Begin
UserNameLen := 255;
SetLength(userName, UserNameLen) ;
If GetUserName(PChar(UserName), UserNameLen) Then
Result := Copy(UserName,1,UserNameLen - 1)
Else
Result := 'Unknown';
End;
--- End code ---
Right now i get
--- Code: ---unit1.pas(256,15) Error: Identifier not found "getUserName"
--- End code ---
Is there names are different or i forget add something to "uses" ?
Regards
eny:
Try adding 'windows' to the uses section.
seba22:
Thank You for answer, think You have right.
Right now I can't see that error about get host and username...
But after adding Windows to uses i get new errors... and i'm unable to compile project.
I want print files in folder so i have following part of code. //it's just example
--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var
SR: TSearchRec;
Fik : Integer;
const
patch:string = 'c:\\';
begin
patch:=edit1.text;
Fik := FindFirst( patch+ '*.*', faAnyFile, SR);
while (Fik = 0) do
begin
listbox1.items.add(AnsiToUtf8(patch+sr.Name));
Fik := FindNext(SR);
end;
FindClose(SR);
memo1.lines:=listbox1.items;
end;
--- End code ---
And error is:
--- Code: ---unit1.pas(234,14) Error: Incompatible type for arg no. 1: Got "TSearchRec", expected "LongWord"
--- End code ---
And it's pointing here
--- Code: ---FindClose(SR);
--- End code ---
SR i think have to be TSearchRec...
If i remove "Windows" from uses it's working perfect...
Any idea ?
Regards
seba22:
I found the solution.
Add SysUtils before command FindClose.
--- Code: ---SysUtils.FindClose(SR);
--- End code ---
Navigation
[0] Message Index