Solved

Alfabet in in Array!

Posted on 2001-08-04
2
525 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
[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
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 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