summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-03 10:50:49 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-03 10:50:49 +0000
commit4d3dbec5a9fdaa97792c107073083e7489ea605e (patch)
treecdd46c4a8028e9c22552999f429394e8af7734dc
parent8a3b02508005b580613b95f0e02811a4392a2fc2 (diff)
downloadfpGUI-4d3dbec5a9fdaa97792c107073083e7489ea605e.tar.xz
* Added a RandomData unit to the examples/gui directory.
* Updated the ComboBox demo to use the RandomData unit.
-rw-r--r--examples/gui/combobox/comboboxtest.lpi10
-rw-r--r--examples/gui/combobox/comboboxtest.lpr2
-rw-r--r--examples/gui/combobox/extrafpc.cfg2
-rw-r--r--examples/gui/combobox/frm_main.pas33
-rw-r--r--examples/gui/common/randomdata.pas265
5 files changed, 304 insertions, 8 deletions
diff --git a/examples/gui/combobox/comboboxtest.lpi b/examples/gui/combobox/comboboxtest.lpi
index 41183e45..c950242d 100644
--- a/examples/gui/combobox/comboboxtest.lpi
+++ b/examples/gui/combobox/comboboxtest.lpi
@@ -32,7 +32,7 @@
<PackageName Value="fpgui_package"/>
</Item1>
</RequiredPackages>
- <Units Count="2">
+ <Units Count="3">
<Unit0>
<Filename Value="comboboxtest.lpr"/>
<IsPartOfProject Value="True"/>
@@ -43,10 +43,18 @@
<IsPartOfProject Value="True"/>
<UnitName Value="frm_main"/>
</Unit1>
+ <Unit2>
+ <Filename Value="../common/randomdata.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="RandomData"/>
+ </Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
+ <SearchPaths>
+ <OtherUnitFiles Value="/home/graemeg/programming/fpgui.wc/examples/gui/common/"/>
+ </SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
diff --git a/examples/gui/combobox/comboboxtest.lpr b/examples/gui/combobox/comboboxtest.lpr
index a3a38da1..313a9c0f 100644
--- a/examples/gui/combobox/comboboxtest.lpr
+++ b/examples/gui/combobox/comboboxtest.lpr
@@ -6,7 +6,7 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
- Classes, fpgfx, frm_main;
+ Classes, fpgfx, frm_main, RandomData;
procedure MainProc;
var
diff --git a/examples/gui/combobox/extrafpc.cfg b/examples/gui/combobox/extrafpc.cfg
index 073dc4b6..a68a9d08 100644
--- a/examples/gui/combobox/extrafpc.cfg
+++ b/examples/gui/combobox/extrafpc.cfg
@@ -1,5 +1,5 @@
-FUunits
--Fu../../../lib
+-Fu../../../lib;../common
-Xs
-XX
-CX
diff --git a/examples/gui/combobox/frm_main.pas b/examples/gui/combobox/frm_main.pas
index 2b834b51..b0be0713 100644
--- a/examples/gui/combobox/frm_main.pas
+++ b/examples/gui/combobox/frm_main.pas
@@ -39,13 +39,17 @@ type
lblName4: TfpgLabel;
cbAllowNew: TfpgComboBox;
{@VFD_HEAD_END: MainForm}
- procedure AfterCreate; override;
+ constructor Create(AOwner: TComponent); override;
+ procedure AfterCreate; override;
end;
{@VFD_NEWFORM_DECL}
implementation
+uses
+ RandomData;
+
{@VFD_NEWFORM_IMPL}
procedure TMainForm.cbAutoCompleteChanged(Sender: TObject);
@@ -69,9 +73,16 @@ begin
end;
procedure TMainForm.btnAdd1Clicked(Sender: TObject);
+var
+ Gender: TGender;
+ n: string;
begin
- Combo1.Items.Add(Format('Item %2d', [Combo1.Items.Count]));
- EditCombo1.Items.Add(Format('Item %2d', [EditCombo1.Items.Count]));
+ Gender := TGender(Random(2));
+ n := RandomFullName(Gender);
+ Combo1.Items.Add(n);
+ EditCombo1.Items.Add(n);
+ Combo1.Items.Sort;
+ EditCombo1.Items.Sort;
end;
procedure TMainForm.btnFocusClicked(Sender: TObject);
@@ -91,12 +102,24 @@ end;
procedure TMainForm.btnAdd10Clicked(Sender: TObject);
var
i: integer;
+ Gender: TGender;
+ n: string;
begin
for i := 1 to 10 do
begin
- Combo1.Items.Add(Format('Item %2d', [Combo1.Items.Count]));
- EditCombo1.Items.Add(Format('Item %2d', [EditCombo1.Items.Count]));
+ Gender := TGender(Random(2));
+ n := RandomFullName(Gender);
+ Combo1.Items.Add(n);
+ EditCombo1.Items.Add(n);
end;
+ Combo1.Items.Sort;
+ EditCombo1.Items.Sort;
+end;
+
+constructor TMainForm.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ Randomize;
end;
procedure TMainForm.AfterCreate;
diff --git a/examples/gui/common/randomdata.pas b/examples/gui/common/randomdata.pas
new file mode 100644
index 00000000..94d8586a
--- /dev/null
+++ b/examples/gui/common/randomdata.pas
@@ -0,0 +1,265 @@
+{
+ fpGUI - Free Pascal GUI Toolkit
+
+ Copyright (C) 2006 - 2008 See the file AUTHORS.txt, included in this
+ distribution, for details of the copyright.
+
+ See the file COPYING.modifiedLGPL, included in this distribution,
+ for details about redistributing fpGUI.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ Description:
+ This unit allows you to generate random data. This is very handy
+ for testing purposes.
+ This code originates from the InstantObjects project, but has been
+ adapted for our needs.
+}
+
+unit RandomData;
+
+{$mode objfpc}{$H+}
+
+interface
+
+type
+ TGender = (gnMale, gnFemale);
+
+function RandomName: string;
+function RandomCompanyName: string;
+function RandomEmail(const PersonName, DomainName: string): string;
+function RandomFirstName(Gender: TGender): string;
+function RandomFullName(Gender: TGender): string;
+function RandomLastName: string;
+function RandomNumber(Len: Integer): string;
+function RandomStreet: string;
+function RandomCity: string;
+
+implementation
+
+uses
+ SysUtils;
+
+const
+ Letters = ['a'..'z'];
+ Vowels = ['a', 'e', 'i', 'o', 'u', 'y'];
+ Consonants = Letters - Vowels;
+
+ SmartPrefixes: array[0..19] of string = (
+ 'cor', 'pri', 'pre', 'neo', 'new', 'or', 'hi', 'inter',
+ 'u', 'i', 'core', 'xo', 'xe', 'xor', 'xer', 'qua', 'gen',
+ 'in', 're', 'tri');
+
+ SmartSuffixes: array[0..12] of string = (
+ 'teq', 'tex', 'tec', 'nix', 'lix', 'tor', 'max', 'time', 'qua',
+ 'paq', 'pac', 'nic', 'nec');
+
+ FirstNames: array[TGender, 0..33] of string = ((
+ 'Anthony', 'Brian', 'Charles', 'Christopher', 'Daniel', 'David', 'Donald',
+ 'Edward', 'George', 'James', 'Jason', 'Jeff', 'John', 'Joseph', 'Kenneth',
+ 'Kevin', 'Mark', 'Michael', 'Paul', 'Richard', 'Robert', 'Ronald', 'Steven',
+ 'Thomas', 'William', 'Graeme', 'Jaco', 'Martin', 'Sam', 'Dale', 'Johan',
+ 'Zayn', 'Xiam', 'René'), (
+ 'Barbara', 'Betty', 'Carol', 'Deborah', 'Donna', 'Dorothy', 'Elizabeth',
+ 'Helen', 'Jennifer', 'Karen', 'Kimberly', 'Laura', 'Linda', 'Lisa',
+ 'Margaret', 'Maria', 'Mary', 'Michelle', 'Nancy', 'Patricia', 'Ruth',
+ 'Sandra', 'Sarah', 'Sharon', 'Susan', 'Debbie', 'Anthea', 'Theonette',
+ 'Amelia', 'Adrie', 'Petro', 'Yolanda', 'Zelda', 'René'));
+
+ LastNames: array[0..53] of string = (
+ 'Adams', 'Allen', 'Anderson', 'Baker', 'Brown', 'Campbell', 'Carter',
+ 'Clark', 'Collins', 'Davis', 'Edwards', 'Evans', 'Garcia', 'Gonzalez',
+ 'Green', 'Hall', 'Harris', 'Hernandez', 'Hill', 'Jackson', 'Johnson',
+ 'Jones', 'King', 'Lee', 'Lewis', 'Lopez', 'Martin', 'Martinez', 'Miller',
+ 'Mitchell', 'Moore', 'Nelson', 'Parker', 'Perez', 'Phillips', 'Roberts',
+ 'Robinson', 'Rodriguez', 'Scott', 'Smith', 'Taylor', 'Thomas', 'Thompson',
+ 'Turner', 'Walker', 'White', 'Williams', 'Wilson', 'Wright', 'Young',
+ 'Geldenhuys', 'Welgens', 'Botha', 'Guthrie');
+
+ Adjectives: array[0..19] of string = (
+ 'Intelligent', 'Smart', 'Wise', 'Bright', 'Essential', 'Basic', 'Happy',
+ 'Precise', 'Fast', 'Express', 'Simple', 'Good', 'Deluxe', 'Perfect',
+ 'Star', 'Future', 'Millenium', 'Solid', 'Sure', 'Great');
+
+ CompanySuffixes: array[0..19] of string = (
+ 'Computers', 'Computing', 'Software', 'Technologies', 'Consulting', 'Food',
+ 'Furniture', 'Textiles', 'Wear', 'Toys', 'Adventures', 'Services', 'Tools',
+ 'Accessories', 'Entertainment', 'Flowers', 'Equipment', 'Items',
+ 'Architecture', 'Knowledge');
+
+ CompanyTypes: array[0..2] of string = (
+ 'Corp.', 'Inc.', 'Ltd.');
+
+ StreetPrefixes: array[0..3] of string = (
+ 'North', 'East', 'South', 'West');
+
+ StreetBeginnings: array[0..16] of string = (
+ 'Salt', 'Sun', 'Moon', 'Stone', 'Rock', 'Clear', 'White', 'Green',
+ 'Corn', 'Shore', 'Cotton', 'Oak', 'Water', 'Bright', 'New', 'Old',
+ 'Apple');
+
+ StreetEndings: array[0..6] of string = (
+ 'wood', 'dale', 'land', 'bridge', 'lake', 'hill', 'field');
+
+ StreetTypes: array[0..7] of string = (
+ 'Street', 'Road', 'Avenue', 'Place', 'Court', 'Boulevard', 'Drive',
+ 'Parkway');
+
+ Cities: array[0..36] of string = (
+ 'Alabama', 'Atlanta', 'Boston', 'Chicago', 'Cincinnati', 'Dallas', 'Denver',
+ 'Detroit', 'Houston', 'Indianapolis', 'Kansas City', 'Las Vegas',
+ 'Los Angeles', 'Memphis', 'Miami', 'Minneapolis', 'Nashville',
+ 'New Orleans', 'New York', 'Oklahoma', 'Omaha', 'Philadelphia',
+ 'Pittsburgh', 'Portland', 'San Diego', 'San Fransisco', 'Seattle', 'Tampa',
+ 'Utah', 'Washington', 'Somerset West', 'Cape Town', 'Bloemfontein',
+ 'Durban', 'Pretoria', 'London', 'Paris');
+
+ DomainSuffixes: array[0..6] of string = (
+ 'com', 'org', 'net', 'edu', 'gov', 'co.za', 'co.uk');
+
+
+function RandomStr(List: array of string): string;
+begin
+ Result := List[Random(Length(List))];
+end;
+
+function RandomLetter: Char;
+begin
+ Result := Chr(Ord('a') + Random(Ord('z') - Ord('a')));
+end;
+
+function RandomConsonant: Char;
+begin
+ repeat
+ Result := RandomLetter;
+ until Result in Consonants;
+end;
+
+function RandomVowel: Char;
+begin
+ repeat
+ Result := RandomLetter;
+ until Result in Vowels;
+end;
+
+function RandomName: string;
+
+ function SmartName: string;
+ begin
+ Result := RandomStr(SmartPrefixes) + RandomStr(SmartSuffixes);
+ end;
+
+ function CombiName: string;
+ begin
+ Result := RandomConsonant + RandomVowel;
+ if Odd(Random(2)) then
+ Result := Result + RandomConsonant;
+ Result := Result + RandomStr(SmartSuffixes);
+ end;
+
+ function TripletName: string;
+ var
+ I: Integer;
+ begin
+ Result := '';
+ for I := 1 to 3 do
+ begin
+ Result := Result + RandomConsonant + RandomVowel;
+ if Random(10) = 1 then
+ Result := Result + RandomConsonant;
+ end;
+ end;
+
+begin
+ case Random(3) of
+ 0: Result := SmartName;
+ 1: Result := CombiName;
+ 2: Result := TripletName;
+ end;
+ Result[1] := UpCase(Result[1]);
+end;
+
+function RandomCompanyName: string;
+begin
+ if Random(3) = 0 then
+ Result := RandomStr(Adjectives)
+ else
+ Result := RandomName;
+ Result := Result + ' ' + RandomStr(CompanySuffixes) + ' ' +
+ RandomStr(CompanyTypes);
+end;
+
+function RandomEmail(const PersonName, DomainName: string): string;
+var
+ Name, FirstName, LastName, Suffix: string;
+ I: Integer;
+begin
+ I := Pos(' ', PersonName);
+ if I > 0 then
+ begin
+ FirstName := Copy(PersonName, 1, Pred(I));
+ LastName := PersonName;
+ Delete(LastName, 1, I);
+ end else
+ begin
+ FirstName := PersonName;
+ LastName := '';
+ end;
+ case Random(3) of
+ 0: Name := FirstName + '.' + LastName;
+ 1: Name := Copy(FirstName, 1, 1) + Copy(LastName, 1, 1);
+ 2: Name := Copy(FirstName, 1, 1) + '_' + LastName;
+ end;
+ if Random(10) <> 0 then // 9 of 10 have .com
+ Suffix := DomainSuffixes[0] else
+ Suffix := RandomStr(DomainSuffixes);
+ Result := LowerCase(Name + '@' + DomainName + '.' + Suffix);
+end;
+
+function RandomFirstName(Gender: TGender): string;
+begin
+ Result := FirstNames[Gender, Random(Length(FirstNames[gnMale]))];
+end;
+
+function RandomFullName(Gender: TGender): string;
+begin
+ Result := RandomFirstName(Gender) + ' ' + RandomLastName;
+end;
+
+function RandomLastName: string;
+begin
+ Result := RandomStr(LastNames);
+end;
+
+function RandomNumber(Len: Integer): string;
+begin
+ Result := '';
+ while Len > 0 do
+ begin
+ Result := Result + Chr(Ord('0') + Random(10));
+ Dec(Len);
+ end;
+end;
+
+function RandomStreet: string;
+begin
+ if Random(8) = 0 then
+ Result := RandomStr(StreetPrefixes) + ' '
+ else
+ Result := '';
+ Result := Result
+ + RandomStr(StreetBeginnings)
+ + RandomStr(StreetEndings) + ' '
+ + RandomStr(StreetTypes) + ' '
+ + IntToStr((Random(499) + 1) div (Random(9) + 1) + 1);
+end;
+
+function RandomCity: string;
+begin
+ Result := RandomStr(Cities);
+end;
+
+
+end.