Autor Beitrag
lemmond1976
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66



BeitragVerfasst: Mi 19.03.03 13:29 
Hallo, mal eine Frage zur obengenannten API-Funktion:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
const MAX_COMPUTERNAME_LENGTH = 50;

function TForm1.GetmyUserName: String;

var
  Buffer: Array[0..MAX_COMPUTERNAME_LENGTH+1] of Char;
  Size: DWORD;
begin
  size:=1024;
  Windows.GetUserName(Buffer, Size);
  Result:=StrPas(Buffer);
end;

Nach einem Klick auf einen Button wird der Username korrekt angezeigt.
Wenn ich die Funktion im OnCreate-Ereignis des Formulars aufrufe, dann steht dort nur Müll.

Danke für Eure Antwort !

Gruss
lemmond

Moderiert von user profile iconKlabautermann: Code-Tags hinzugefügt.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 19.03.03 13:50 
Hallo,

versuche einmal folgendes:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function GetNetzName(aTyp:Integer):String;
var pc  :array[0..255] of Char;
    size:DWord;
begin
  size:=SizeOf(pc);
  if (WNetGetUser('', pc, size)=NO_ERROR) then Result:=StrPas(pc)
    else Result:='';
  //Result:=UpperCase(Result);
end; // GetNetzName

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.03.03 18:13 
Geht wunderbar:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
const MAX_COMPUTERNAME_LENGTH = 50; 

function GetmyUserName: String;
var
  Buffer: Array[0..MAX_COMPUTERNAME_LENGTH+1] of Char;
  Size: DWORD;
begin
  size:=1024;
  Windows.GetUserName(Buffer, Size);
  Result:=StrPas(Buffer);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := GetMyUserName();
end;
lemmond1976 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 66



BeitragVerfasst: Do 20.03.03 11:06 
@smiegel: Dein Quellcode funktioniert einwandfrei.
Danke !