[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
2
Medium Priority
?
528 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 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
    //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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 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