0

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.

TLama
  • 75,147
  • 17
  • 214
  • 392
  • Sorry, but this makes no sense to me. What is your aim ? Why do you want to keep track of the edit box text with a variable ? You can read, or update that variable before you use it. In your current code you're creating an edit box and assigning a text from the `server` variable, nothing more. – TLama Feb 11 '14 at 10:18
  • I wanted to have a text box that has a default IP address in it, but also want to allow it to be updated. Then that IP will be used in a registry key later on in the script. I just can't seem to get it to update if someone enters alters the text already set. – copyandpaster Feb 11 '14 at 11:52
  • Well, then you don't actually need that variable. Check [`this example`](http://pastebin.com/UUN0HLNE) to see why. It would be possible to do exactly what you've asked but that would be wrong way. So called [`scripted constants`](http://jrsoftware.org/ishelp/topic_scriptconstants.htm) is the right way. – TLama Feb 11 '14 at 12:09
  • Oh, and in the example you gave, you don't actually attach any events to receive the change notification. – Deanna Feb 13 '14 at 15:31

1 Answers1

0

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;
  • You could "shorten" your condition to `if Key in ['{', '}', '<', '>', '[', ']', '``', '~', '(', ')', '#', '%', '*', ';', ':', ',', '?', '@'] then`. Also, there's no need to evaluate the `Key` four times, I mean, you could write it at once from `or` operators. – TLama Feb 26 '14 at 16:24