Delphi Incompatible Types

I am trying to use an old unit (xbase.pas) that I have not used in years. Any function I try to use gives me the following error...

Incompatible types: 'HWND' and 'String'

The function in xbase.pas is... function space(Space_Count: integer) : string;

I am naming a variable 'poo:string' in button procedure. I can assign a value to poo with space() no problem. But when I try to use the value, I get the 'Incompatible types: 'HWND' and 'String'' error message.

Can anyone help me?
LVL 7
lacrewgaAsked:
Who is Participating?
 
rfwoolfCommented:
sorry if im mistaken here, but it seems likely that the error is generated by misusing messagebox.
Try instead showmessage(poo);
If would seem that messagebox is expecting a HWND (a window handle) as its parent (if I remember the syntax correctly). Showmessage only requires a string.
0
 
rfwoolfCommented:
By your description it would seem that the xbase.pas unit is fine and that function space is fine, but the problem comes in when you 'try to use the value'. So you would have to show us an example of you using the value.

long story short: we need more.

Another thought, when you 'use the value' make sure that you  aren't accidentally calling a procedure in unit xbase. For example xbase might have a function called abort. If you call abort in your unit, it will call xbase.abort instead of sysutils.abort or whatever.
0
 
rfwoolfCommented:
By your description it would seem that the xbase.pas unit is fine and that function space is fine, but the problem comes in when you 'try to use the value'. So you would have to show us an example of you using the value.

long story short: we need more.

Another thought, when you 'use the value' make sure that you  aren't accidentally calling a procedure in unit xbase. For example xbase might have a function called abort. If you call abort in your unit, it will call xbase.abort instead of sysutils.abort or whatever.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
lacrewgaAuthor Commented:
Thanks for responding.

This is the header of the xbase.pas unit...

unit Xbase;
{Object Pascal routines that emulate popular xBase routines}
interface
Uses
 SysUtils,
 Windows;
function Pad(InString: String; Len: Integer): String;
function LPad(InString: String; Len: Integer): String;
function LeftString(InString: String; Len: Integer): String;
function RightString(InString: String; Len: Integer): String;
function Replicate(Ch: Char; Len: Integer): String;
function Space(Len: Integer): String;

This is the body of the Space() function...

function Space(Len: Integer): String;
begin
 Result := Replicate(' ', Len);
end;

This is how I am using the code...

procedure TForm1.Button1Click(Sender: TObject);
var
poo:string;
begin
poo := space(20);
messagebox(poo);
end;

poo initializes, but the messagebox gives me the error message(all functions in xbase.pas gives error when trying to use value).

Thanks again.
0
 
lacrewgaAuthor Commented:
You are absolutely right. I sincerely appreciate your quick response and your expertise.
0
 
rfwoolfCommented:
you're welcome. By the way I've just looked up TApplication.Messagebox, and here's the syntax:
Delphi] function MessageBox(const Text: PAnsiChar; const Caption: PAnsiChar; Flags: Integer): Integer;
As you can see it doesn't ask for a handle, but perhaps somehow your version requires one, or the Messagebox method that is being called is not the TApplication one. In my delphi IDE if I hover over a method it will tell me what unit it belongs to. I seem to recall that some message methods do require you specify a handle, and I usually specify the application if possible.
0
 
rfwoolfCommented:
Ahh here's a clue, from the same help file:
TApplication.MessageBox is an encapsulation of the Windows API MessageBox function. TApplication's encapsulation of MessageBox automatically supplies the missing window handle parameter needed for the Windows API function.
Either your version of Delphi doesn't do this, or, you aren't using TApplication.MessageBox. But what it's saying is that ultimately MessageBox does want a windows handle, but this is supplied automatically (at least in my version).
Anyway, you have found the problem :)
0
 
lacrewgaAuthor Commented:
I have dabbled in so many programming languages, I sometimes get confused. I've done so much development in Foxpro, the functions and procedures come very natural. It is nice to know that there are others out there still working with delphi. By the way, that was the first question I ever asked on EE. Everyone should hope they get such timely response and resolution. Again... Thanks.
0
 
lacrewgaAuthor Commented:
By the way I'm using D5 (dinosaur?) but still kickin!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.