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
Solved

Alfabet in in Array!

Posted on 2001-08-04
2
522 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert GUI app into console app for Win32 Env 5 109
Delphi...Split view - idea? 1 87
Delphi: barcode reading on android platform 1 51
Delphi Seattle StructureView color 1 14
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

765 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