?
Solved

Delphi Incompatible Types

Posted on 2009-04-29
9
Medium Priority
?
2,164 Views
Last Modified: 2013-11-23
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?
0
Comment
Question by:lacrewga
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24266128
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
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24266134
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
 
LVL 7

Author Comment

by:lacrewga
ID: 24266169
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Accepted Solution

by:
rfwoolf earned 2000 total points
ID: 24266189
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
 
LVL 7

Author Comment

by:lacrewga
ID: 24266220
You are absolutely right. I sincerely appreciate your quick response and your expertise.
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24266270
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
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24266299
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
 
LVL 7

Author Comment

by:lacrewga
ID: 24266354
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
 
LVL 7

Author Comment

by:lacrewga
ID: 24266358
By the way I'm using D5 (dinosaur?) but still kickin!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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