Link to home
Start Free TrialLog in
Avatar of lacrewga
lacrewga

asked on

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?
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

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.
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.
Avatar of lacrewga
lacrewga

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are absolutely right. I sincerely appreciate your quick response and your expertise.
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.
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 :)
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.
By the way I'm using D5 (dinosaur?) but still kickin!