Taggs Posted February 18, 2005 Share Posted February 18, 2005 Any idea's how I can get my computer name in Delphi 3 please.IE MYHOMEPC Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 I thinks its GetComputerName but I want to put this into a variable.Any help would be greatly appriciated Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 Your computer name appears many times in the registry, which you can access via Delphi.HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 Indeed, as you suggested, you could use ...function GetComputerName: string;var buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of char; Size: Cardinal;begin Size := MAX_COMPUTERNAME_LENGTH + 1; Windows.GetComputerName (@buffer, Size); Result := StrPas (buffer)end;... don't know if it works with Delphi 3, it certainly works with Delphi 7! Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 Thanks for the post I'm getting the error :Types of actual and formal var parameters must be identical on this line. Windows.GetComputerName(buffer, Size); Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 Did you forget the "@"? Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 Oops sorry missed it off the post. still get same Error! Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 It might be a "feature" of Delphi 3. Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 An undocumented one Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 Can you post the entire program? Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 Sure, here you gounit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);varbuffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;Size: Cardinal;Result :string;beginSize := MAX_COMPUTERNAME_LENGTH + 1;Windows.GetComputerName(@buffer, Size);Result := StrPas(buffer);end;end.Not much of a program as yet, as I've fallen at the first hurdle! But it will all depend on getting the computer name and looking this up against a database! Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 I'm intrigued as to why the GetComputerName function is within a "FormCreate" method?Try ... (Place a Button on the Form, double click on it and type "ShowMessage (GetComputerName)" inside. Also what do the Labels do??)unit Unit1;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;typeTForm1 = class(TForm)Label1: TLabel;Label2: TLabel;private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.DFM}function GetComputerName; string;varbuffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;Size: Cardinal;beginSize := MAX_COMPUTERNAME_LENGTH + 1;Windows.GetComputerName(@buffer, Size);Result := StrPas(buffer);end;procedure Button1Click(Sender:TObject);begin ShowMessage (GetComputerName)end;end. Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 Still get them! Ignore the labels they are just a message on the screen. It is in create, as when I run the program, it runs a process and then closes with out any interaction from the user! Link to comment Share on other sites More sharing options...
Taggs Posted February 18, 2005 Author Share Posted February 18, 2005 http://www.msfn.org/board/index.php?showtopic=39460&st=0this is what it will be used for! Link to comment Share on other sites More sharing options...
FAT64 Posted February 18, 2005 Share Posted February 18, 2005 All I can say further, is that it definitely works in Delphi 7. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now