Delphi Help!

It was working... now it doesnt... im so gonna throw this pos out the window

Ne ways here is ALL the code:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Borland.Vcl.StdCtrls, System.ComponentModel;

type
TfrmStrings = class(TForm)
lblWord: TLabel;
edtWord: TEdit;
lstModify: TListBox;
btnTransferModify: TButton;
btnRepeat: TButton;
btnClear: TButton;
procedure btnTransferModifyClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmStrings: TfrmStrings;

implementation

{$R *.nfm}

procedure TfrmStrings.btnTransferModifyClick(Sender: TObject);
var
word : string;
i : integer;
NewWord : string;
begin
word := edtWord.Text;
for i := 1 to Length(word) do
begin
if ((word) <> ' ') and (word IN ['a','e','i','o','u'])
and (word IN ['A','E','I','O','U']) then
NewWord := NewWord + word;
end;
lstModify.Items.Add(NewWord);

end;

procedure TfrmStrings.btnClearClick(Sender: TObject);
begin
lstModify.Items.Clear;
end;

end.
 
Last time I used delphi was matric final and been doing c++ and VB now so sometimes get confused between them all :)
 
Try this: (afer you save your current work of course)

-------------------------------------------------------------------------

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Borland.Vcl.StdCtrls, System.ComponentModel;

type
TfrmStrings = class(TForm)
lblWord: TLabel;
edtWord: TEdit;
lstModify: TListBox;
btnTransferModify: TButton;
btnRepeat: TButton;
btnClear: TButton;
procedure btnTransferModifyClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmStrings: TfrmStrings;

implementation

{$R *.nfm}

procedure TfrmStrings.btnTransferModifyClick(Sender: TObject);
var
word : string;
i : integer;
NewWord : string;
begin
word := edtWord.Text;
for i := 1 to Length(word) do
begin
if ((word) <> ' ') and (NOT(Upcase(word) IN ['A','E','I','O','U']))
then
NewWord := NewWord + word;
end;
lstModify.Items.Add(NewWord);

end;

procedure TfrmStrings.btnClearClick(Sender: TObject);
begin
lstModify.Items.Clear;
end;

end.


-------------------------------------------------------------------------
 
Last edited:
Changed:

if ((word) <> ' ') and (word IN ['a','e','i','o','u'])
and (word IN ['A','E','I','O','U'])


to

if ((word) <> ' ') and (NOT(Upcase(word) IN ['A','E','I','O','U']))

To explain in words:

If the current character is not space and is NOT 'A','E','I','O','U' , add it to the NewWord...

etc. for all characters..
 
Multiple condition for a single case ( case statement )

The first question in this assignments asks me to do an if..else statement, which was alright. It then followed on to ask to change it to a case statement.. but the problem i get is for example:

one condition is: if the person is 12 or older but younger than 19, 5km radio button and 10km radio button must be enabled.

i thought i could do this:

12..18 : rad5km.Enabled := True;
12..18 : rad10km.Enabled := True;

but when i do this it gives an error for duplicate case. How do i write it under one case?
 
The first question in this assignments asks me to do an if..else statement, which was alright. It then followed on to ask to change it to a case statement.. but the problem i get is for example:

one condition is: if the person is 12 or older but younger than 19, 5km radio button and 10km radio button must be enabled.

i thought i could do this:

12..18 : rad5km.Enabled := True;
12..18 : rad10km.Enabled := True;

but when i do this it gives an error for duplicate case. How do i write it under one case?

12..18 :
begin
rad5km.Enabled := True;
rad10km.Enabled := True;
end

fixed..
 
12..18 :
begin
rad5km.Enabled := True;
rad10km.Enabled := True;
end

fixed..

ahh of course... must be the pressure clogging my mind.

Stuck with another one.

Change the following for statement to a repeat..until statement. I did it but the program crashes prob cos the repeat is not ending.

var i, count : string;
begin
count := lstModify.Count;
for i := 0 to count-1 do
lstModify.Items.Add(lstModify.Items);
end;


I think i posted this question earlier and thought i had it correct

Edit: This is what i did:

procedure TfrmStrings.btnRepeatClick(Sender: TObject);
var i, count : integer;
begin
count := lstModify.Count;
i := 0;
repeat
lstModify.Items.Add(lstModify.Items)
until i = count;

end;
 
Last edited:
Be sure to toggle the radio buttons to the correct setting too. Nothing is more frustrating than a button with the wrong setting that you can't change because the stupid programmer disabled the button.
 
var i, count : string;
begin
count := lstModify.Count;
for i := 0 to count-1 do
lstModify.Items.Add(lstModify.Items);
end;


I think i posted this question earlier and thought i had it correct


Havent really used those properties of a listbox before!? (Havoc!? :D)

Have no idea but anyways..

Count := lstModify.Count;
Number = 0
Repeat ;
lstModify.Items.Add(lstModify.Items[Number+1]);
Inc(Number)

Until Number = Count-1
 
Last edited:
Nevermind bout the repaet loop... realised my mistake.

Didnt include a statement to increment i by 1 after each repeat

Tested it and the prog works as it should...

Repeat i changed to this:

procedure TfrmStrings.btnRepeatClick(Sender: TObject);
var i, count : integer;
begin
count := lstModify.Count;
i := 0;
repeat
lstModify.Items.Add(lstModify.Items);
i := i + 1;
until i = count;

end;
 
Nevermind bout the repaet loop... realised my mistake.

Didnt include a statement to increment i by 1 after each repeat

Tested it and the prog works as it should...

Repeat i changed to this:

procedure TfrmStrings.btnRepeatClick(Sender: TObject);
var i, count : integer;
begin
count := lstModify.Count;
i := 0;
repeat
lstModify.Items.Add(lstModify.Items);
i := i + 1;
until i = count;

end;


Change that to Inc(i) ;)

---------------------------------------------------------------
Count := lstModify.Count;
Number = 0
Repeat ;
lstModify.Items.Add(lstModify.Items[Number+1]);
Inc(Number)

Until Number = Count-1
 
Three last questions and ill try leave you guys alone:

1. What is the index value of the first item in a ListBox? ( i assume '1')
2. What is the index value of the last item in a ListBox? ( i assume lstModify.Count )

3. What is the data type of the items that MAY be stored in a listbox?
 
If you really want to confuse the hell out of the teacher use an asm block and write your code in assembler. Might take a while though.
 
Three last questions and ill try leave you guys alone:

1. What is the index value of the first item in a ListBox? ( i assume '1') --> Hmm well i know for Radio Group its 0... Not sure about list box though. Id say 0
2. What is the index value of the last item in a ListBox? ( i assume lstModify.Count ) --> Hmm..lstModify.Count -1 i think if the above is true (first index value = 0)

3. What is the data type of the items that MAY be stored in a listbox? --> String?

:rolleyes:
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X