Solved

Alfabet in in Array!

Posted on 2001-08-04
2
516 Views
Last Modified: 2008-03-17
Well here it is:

I have a nummer of buttons.
i want these buttons filled with the letters of
the alfabet.

These buttons are dynamicaly created; depending in how big
the form is. U can have 12 buttons but also 9 or 11.

the problem is that when i have less then 26 buttons
i can not put every letter on the alfabet on every button.

So i must put more letters than 1 on some buttons.

Does sombody has a clue?

const ABC:array[0..26] of  string=('123','a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z');


procedure TForm1.Button1Click(Sender: TObject);
var
i,x,Skip:integer;
arrB:array of TSpeedButton ;
begin
del;
x:=19-1;
skip:=1;
for i := x downto 0 do
begin
SetLength(arrB,20);
arrB[i]:=TSpeedButton.Create(self);
arrB[i].parent:=Panel1;
arrB[i].Align:=altop;
arrB[i].Height:=25 ;
arrb[i].Flat:=true;
arrb[i].tag:=i;
if i >=11 then
begin
if i=11 then
arrb[i].caption:= abc[i]+abc[succ(i)]
else
arrb[i].caption:='s'
end else  begin
arrb[i].caption:=abc[i];
end;
end;
end;


procedure TForm1.Del;
var
i:integer;
c:tcomponent;
begin
for i :=self.ComponentCount-1 downto 0 do
begin
c:=Components[i];
if c is TSpeedButton  then
with Components[i] as TSpeedButton do begin
if tag < 5 then
c.free;
end;
end;

end;

0
Comment
Question by:maatwerk
2 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 300 total points
ID: 6352396
Here is some code that you can use.  I wrote it to place the captions in an array of strings (to make it easier for me to develop and test quickly), but you can easily place the values in an array of dynamically allocated speedbuttons.

Things you will need to customize:

1.  I get 'NumButtons' from Edit1.Text...supply NumButtons with whatever your button count is.
2.  I clear the array of strings...you will need to clear the captions of all the speedbuttons instead
3.  I set the element of a string array corresponding to the ButtonIndex to the current value...instead, just set the speedbutton of the ButtonIndex
4.  You don't need the listbox stuff at the bottom...I used that to display the list of strings

Let me know if you have any questions.


----------------------------------------------------

const ABC:array[0..26] of  string=('123','a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z');


//i am using an array called ButtonStrings to store the captions instead of
//an array of speedbuttons
var
    ButtonStrings :array[0..26] of string;


procedure TForm1.Button1Click(Sender: TObject);
var
    NumButtons, CurrentLetter, ButtonIndex :integer;
    ButtonsPerLetter, CurrentButton :real;
    i :integer;
begin
    //clear your speedbutton captions here
    for i := 0 to 26 do
        ButtonStrings[i] := '';

    //this is the number of speedbuttons you have
    NumButtons := StrToInt(Edit1.Text);

    ButtonsPerLetter := NumButtons / Length(ABC);
    CurrentLetter := 0;
    CurrentButton := 0;
    while (CurrentLetter <= High(ABC)) do begin
        ButtonIndex := trunc(CurrentButton);
        if ButtonIndex >= NumButtons then
            ButtonIndex := NumButtons - 1;

        //set your speed button caption here
        ButtonStrings[ButtonIndex] := ButtonStrings[ButtonIndex] + ABC[CurrentLetter];

        CurrentButton := CurrentButton + ButtonsPerLetter;
        Inc(CurrentLetter);
    end;


    //this is just code to display the strings in the listbox...not needed if
    //you are displaying them on speedbuttons
    ListBox1.Clear;
    for i := 0 to NumButtons - 1 do
        ListBox1.Items.Add(ButtonStrings[i]);
end;
0
 

Author Comment

by:maatwerk
ID: 6353577
Well i am very happy man now. It took some time to customise it in my procedure.

But im very satisfied
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now