Jump to content

Computer Name


Recommended Posts


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

Sure, here you go

unit Unit1;

interface

uses

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);

var

buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;

Size: Cardinal;

Result :string;

begin

Size := 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! :blushing:

But it will all depend on getting the computer name and looking this up against a database!

Link to comment
Share on other sites

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;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

Label2: TLabel;

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.DFM}

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;

procedure Button1Click(Sender:TObject);

begin

ShowMessage (GetComputerName)

end;

end.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...