Recent

Author Topic: Adding values to a combo box  (Read 14839 times)

dhouard

  • Newbie
  • Posts: 1
Adding values to a combo box
« on: May 05, 2004, 07:32:14 pm »
My problems is that I'm not sure what method I must use to add values to a combobox when I start the program.

I thought it was combo.additem('value') but whenever I try to do so I have an error.

Here's the code

procedure TForm1.Form1Create(Sender: TObject);
begin
   frecu.additem('valor1');
end;


'Frecu' is the combobox. I try to add the values when the form is created.

The error is:

Cannot access a private field of an object here.

If the code is

begin
   TForm1.frecu.additem('valor1');
end;[/i]


The error is:


Only Class methods can be reffered with class references

I don't know what I'm doing wrong...

Thanks.
Dhouard.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Adding values to a combo box
« Reply #1 on: May 05, 2004, 09:08:06 pm »
I don't get this error, when I try do the same. I get a different error.

Try this:
procedure TForm1.Form1Create(Sender: TObject);
begin
  Frecu.Items.Add('Test Value 1');
  Frecu.AddItem('Test Value 2', nil);
end;

Raiden

  • New member
  • *
  • Posts: 5
Adding values to a combo box
« Reply #2 on: May 11, 2004, 07:41:50 pm »
I receive the same error (the first of them) when I try to show a messagebox :S

PS: dhouard, yo de Málaga  :lol:

Weitentaaal

  • Jr. Member
  • **
  • Posts: 59
Re: Adding values to a combo box
« Reply #3 on: October 15, 2020, 02:58:21 pm »
Items.Add Worked For me

AL

  • Full Member
  • ***
  • Posts: 209
Re: Adding values to a combo box
« Reply #4 on: October 15, 2020, 03:54:39 pm »
May be your form1 is not created.
Do you have application.createform(tform1,form1) in your project.lpr file?
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

lucamar

  • Hero Member
  • *****
  • Posts: 3238
Re: Adding values to a combo box
« Reply #5 on: October 15, 2020, 03:55:03 pm »
I thought it was combo.additem('value') but whenever I try to do so I have an error.

The message is not very informative but AddItem() is declared as:
Code: Pascal  [Select][+][-]
  1. procedure AddItem(const Item: string; AnObject: TObject); virtual;
so if you want to use it you have to do:
Code: Pascal  [Select][+][-]
  1.    frecu.additem('valor1', Nil);
as Vincent showed.

Quote
If the code is
Code: [Select]
begin
   TForm1.frecu.additem('valor1');
end;
The error is:
Only Class methods can be reffered with class references

That one is quite correct: you're trying to access a field of the object but you're using a class reference, which can only be done with class methods, which are those declared as, e.g.:
Code: Pascal  [Select][+][-]
  1. class function Something(AParam: Integer): String;

HTH!
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

sstvmaster

  • Full Member
  • ***
  • Posts: 176
Re: Adding values to a combo box
« Reply #6 on: October 16, 2020, 12:05:06 am »
Perfect, solved after 16 Years.  ;)
Windows 10 (64 bit)
Lazarus: 2.0.10 / Trunk x32

 

TinyPortal © 2005-2018