Recent

Author Topic: TComboBox question  (Read 2995 times)

Badger

  • Full Member
  • ***
  • Posts: 144
TComboBox question
« on: December 26, 2014, 04:49:56 am »
Recently started using Lazarus.  Started with Delphi 3 then Delphi 7 and then upgraded to RAD XE5 Starter Edition.  What a waste of money that was!!  What kind of an IDE is it that only has limited functionality simply because you don't want to/can't justify paying the exorbitant price of the Professional Version.  As far as I'm concerned Embarcadero can stick their software where the sun don't shine!

Enough bitching, can anyone help with my problem.  I have a combobox that is created at run time with read only set to true.  If you select the item "Other..." the read only switches to false.  However, when I try to enter any text I get an out of bounds error.  Do I need to change any other properties?

As an additional question, is there any reason why hovering over a variable while debugging will give me its value while hovering over a component property gives an error.  It would be a great help if this worked.

Badger
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v2.4.4  FPC 3.2.2   Win 32/64

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TComboBox question
« Reply #1 on: December 26, 2014, 05:35:59 am »
I have a combobox that is created at run time with read only set to true.  If you select the item "Other..." the read only switches to false.  However, when I try to enter any text I get an out of bounds error.  Do I need to change any other properties?
Show your code. What "Other..." thing is this we have no idea.
As an additional question, is there any reason why hovering over a variable while debugging will give me its value while hovering over a component property gives an error.  It would be a great help if this worked.
http://wiki.freepascal.org/Lazarus_Faq#How_can_I_inspect_properties.3F

Badger

  • Full Member
  • ***
  • Posts: 144
Re: TComboBox question
« Reply #2 on: December 26, 2014, 06:50:39 am »
I found the answer.

Code for creating the comboboxes is:-

Code: [Select]
if CommitteeNumber>OldCommitteeNumber then
  begin
     //Layout the combo Boxes etc
    SetLength(ComboArray,CommitteeNumber);
    x:=OldCommitteeNumber;
    Repeat
      //Create ComboBox
      ComboArray[x]:=TCombobox.Create(Self);
      ComboArray[x].Parent:=CommitteeBox;
      ComboArray[x].Tag := x;
      //Add properties
      With ComboArray[x] do
      begin
        Left:=10;
        Top:=125+x*(height+5);
        DropDownCount:=12;
        ReadOnly:=True;
        Width:=140;
        Style:=csDropDownList;
        //add items
       items.Add(title.Items[title.ItemIndex]);
       items.Add('Vice '+title.Items[title.ItemIndex]);
       items.Add('vice '+title.Items[title.ItemIndex]+' 1');
       items.Add('Vice '+title.Items[title.ItemIndex]+' 2');
       items.Add('Vice '+title.Items[title.ItemIndex]+' 3');
       items.Add('Secretary');
       items.Add('Assistant Secretary');
       items.Add('Minute Secretary');
       items.Add('Treasurer');
       items.Add('Assistant Treasurer');
       items.Add('Committee Member');
       items.Add('Other...');
        //Add events
        OnChange:= @OnComboChange;
        inc(x);
      end;
    until x=CommitteeNumber ;
  end; 

Onchange code was:=

Code: [Select]
procedure TCommitteeStructureForm.OnComboChange(Sender: TObject);
var
  Num:Integer;
begin
  //Other Selected??
  Num := (Sender as TComboBox).Tag;
  If ComboArray[Num].items[ComboArray[Num].ItemIndex]='Other...' then
  begin
    ComboArray[Num].ReadOnly:=False;
  end;
  if ComboArray[Num].ItemIndex in[0..10] then
    ComboArray[Num].ReadOnly:=True;;
end;

By changing the onchange code to:-
Code: [Select]
  If ComboArray[Num].text='Other...' then
  begin
    ComboArray[Num].ReadOnly:=False;
  end;
  if ComboArray[Num].ItemIndex in[0..10] then
    ComboArray[Num].ReadOnly:=True;;
end;

It works fine. The only explanation I can see is that as soon as you type into the input box you change the itemindex number to one that is out of bounds (-1 perhaps?).

Thanks for making me think harder  :D

Badger
   
Badger
(A bad tempered, grumpy animal that sleeps most of the winter!)

If at first you don't succeed - you're running about average!

I'm using Windows 10 Lazarus v2.4.4  FPC 3.2.2   Win 32/64

 

TinyPortal © 2005-2018