[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Alfabet in in Array!

Posted on 2001-08-04
Medium Priority
528 Views
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
Question by:maatwerk
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 5

Accepted Solution

scrapdog earned 1200 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
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
end;
0

Author Comment

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…