问题描述:

I have what I think is a simple problem, just can't get my head around it.

Trying to write a script with a single page.

A combobox and a edit box.

The combobox is working fine, I am able to get the contents of it depending on what has been selected.

My Edit box however, I can't get it to update the variable if the text in the box is altered.

[Code]

var

server: string;

procedure InitializeWizard;

var

Edit: TNewEdit;

begin

server := '127.0.0.1';

Edit := TNewEdit.Create(CustomPage);

Edit.Top := DescLabel2.Top + DescLabel2.Height + 6;

Edit.Width := CustomPage.SurfaceWidth div 2 - ScaleX(8);

Edit.Text := server;

Edit.Parent := CustomPage.Surface;

Cant figure out what I'm doing wrong.

网友答案:

Maybe a piece of my code will help:

// The name of the virtual machine
Edit1 := TEdit.Create(WizardForm);
with Edit1 do
 begin
  Parent     := Panel3;
  Left       := ScaleX(Offset);
  Top        := ScaleY(0*LineHeight) + ScaleY(5);
  Width      := ScaleX(145);
  Height     := LineHeight;
  Text       := '';
  ShowHint   := True;
  Hint       := ExpandConstant('{cm:VBoxConfig1Hint}');
  TabOrder   := 0;
  OnExit     := @GetVM_Name;
  OnKeyPress := @CheckEditInput;
 end;

Mark the OnExit !! this piece you forgot to program.

Procedure GetVM_Name(Sender: TObject);
// Get the machineName
{}
begin
 VirtualMachineName := AddQuotes(Edit1.Text);
end;

To avoid unwanted input create a on checkinput routine. An example looks like:

Procedure CheckEditInput(Sender: TObject; var Key: char);
// This procedure checks if the character entered is a wanted one
{} 
begin
 if (Key = '{') or (Key = '}') or (Key = '<') or (Key = '>') then
  begin
   Beep;
   Key := #0;
  end;
 if (Key = '[') or (Key = ']') or (Key = '`') or (Key = '~') then
  begin
   Beep;
   Key := #0;
  end;
 if (Key = '(') or (Key = ')') or (Key = '#') or (Key = '%') or (Key = '*') then
  begin
   Beep;
   Key := #0;
  end;
 if (Key = ';') or (Key = ':') or (Key = ',') or (Key = '?') or (Key = '@') then
  begin
   Beep;
   Key := #0;
  end;
end;
相关阅读:
Top