Solved

Tryin to call a function

Posted on 2004-08-10
3
203 Views
Last Modified: 2010-04-05
Hello,

I have a quick question....  As it is academically related, I am not after answers, just a push in the right direction.  I am studying in isolation though, so any advise would be greatly appreciated!!

Basically, I am trying to do the palindrome thing, and I'm 1/2 way there. I have cleaned the string (removed all non alpha numeric and changed to lowercase), now I am trying to call: procedure reverse(const: string; var T: string);
Which is where I am running into problems.

Here is my code so far:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Variants, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    edtInput: TEdit;
    Palindromes: TMemo;
    SaveDialog1: TSaveDialog;
    Test: TButton;
    procedure TestClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  edtInput: TEdit;
  Palindromes: TMemo;

const
  Chars : Set of Char = ['a'..'z','A'..'Z','0'..'9'];

implementation

{$R *.DFM}

function clean(const S: string): string;
var count: Integer;
begin

for count := 0 To Length(s) do
if S[count] in Chars
  then result := result + S[count];

end;

procedure reverse(const S: string; var T: string);

begin
writeln(test);
// yet to write this part
end;

procedure TForm1.TestClick(Sender: TObject);
var result, input : string;

begin

if length(edtInput.Text) = 0 then
showMessage('Please enter text')
else
input := clean(edtInput.Text);
result := lowercase(s);
showmessage(clean(input));

{ tried top call the procedure here as in: input := reverse(edtInput); but it did not work. I am guessing that I am not passing enough parameters somehow, as in it expecting two strings? }

end;

end.
 

Many thanks.

0
Comment
Question by:south_paw
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
rbohac earned 250 total points
ID: 11767680
two problems in this code

1) S is undefined in your TestClick procedure
2) test is undefined in your reverse procedure

commenting those out allows the code to compile.

You are passing your variable by reference to the reverse function. Instead  the function returning the string, you are passing a pointer to the reverse procedure, so that it can store the value.

To call it do: reverse(edtInput.text,input);

of you can change your reverse procedure to a function:

function reverse(const S: string):String;
begin
Result := 'Reversed String';
end;

and call it like: input := reverse(edtInput.text);
0
 

Author Comment

by:south_paw
ID: 11768272
Thanks rbohac!

I amended it to:

procedure reverse(const S: string; var T: string);
begin

messagebeep(0);

end;

procedure TForm1.TestClick(Sender: TObject);
var input : string;

begin

 if length(edtInput.Text) = 0 then
 showMessage('Please enter text')

 else
 input := clean(edtInput.Text);
 input := lowercase(edtInput.Text);
 showmessage('Cleaned output: ' + clean(input));
 reverse(edtInput.text,input);

end;

end.


The code compiles, and I get the beep at the end. Of interest, I do not have any problems even though S is undefined in my testClick procedure. Wierd.
0
 
LVL 6

Expert Comment

by:rbohac
ID: 11768508
Well actually S is not undefined. By default Delphi initializes a string valiable for you automatically. So actually S = ''
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 105
Delphi application Soap connection 5 104
Graphics32 under Delphi 10.1 Berlin 2 67
Delphi: sending SMS on android platform 1 21
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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