I've "coded" in a few small, easy-to-use nonfunctional programs like VB express and AutoPlay Media Studio (more like scripting) and wanted to kick it up a knotch and heard that Delphi is a great program to use for it. So... I tried it and i am amazed at how completely inconvient the interface is and how completely stupid some of the coding is. For example: "Edit1.Enabled:=" WHY NOT JUST "Edit1.Enabled: or Edit1.Enabled=" But anyway with all of these flaws, i'm sure i can get adjusted to just fine. But i CANNOT get adjusted to a completely lame and stupid coding problem i am having and has caused me to pull out all the hairs in my head. I even made a video just to show you how stupid it is.

I was playing around in the program just for fun and i started trying to make a little interface. Then, i tried to make a tab'd window using radiogroup buttons. I then noticed that if i have 2 or more codes into an if statement, that apparently when i choose one button it choose all of the buttons no matter which one is choosed depeding on if it feels like not choosing it(Joke, but it seriously does that). So, then i decided to error-test it and brake it down to a simple simple task of enabling one Edit box on/off. Code:

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'Yes' then
    Edit1.Enabled:=false;
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'No' then
    Edit1.Enabled:=true;
end;

end.

This allowed me to easily enable/unenable an edit box. -- Yes i know that yes is false and no is true.

So, then i said "one variable works", and tried 2 variables in the if statement. Such as...

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'Yes' then
    Edit1.Enabled:=false;
    Edit2.Enabled:=true;
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'No' then
    Edit1.Enabled:=true;
    Edit2.Enabled:=false;
end;

end.

AND THEN, for some reason... When yes is chosen it unenables both, and when no is chosen it enables 1 and unenables 2. Now... How in the hell does that ever work out to be true? I really don't understand at all, care to give some help on how i can fix this?

--- Video(1.84Mb) - http://files.filefront.com/123avi/;8785433;/fileinfo.html

If I understand correctly, you want both statements to be processed when the if statement is true.

In that case, you need the begin ... end around the statements to be processed when the if statement is true. Otherwise it will only process the first line if the statement is true and the second regardless. It sees the semi-colon as the end of the instruction, so it sees
if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'Yes' then Edit1.Enabled:=false; as one command and
Edit2.Enabled:=true; as a separate command.

You need to use something like
if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'Yes' then
begin
Edit1.Enabled:=false;
Edit2.Enabled:=true;
end;

Hope that helps.

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'Yes' then
begin
Edit1.Enabled:=false;
Edit2.Enabled:=true;
end
else
begin
Edit1.Enabled:=true;
Edit2.Enabled:=false;
end;
end;

Yes, That should do it.

You might want to indent you code between the begin and end. It just makes it a bit more readable.

This article has been dead for over six months. Start a new discussion instead.