GetVersionExW error in BDS2006 - delphi

this works in Delphi 2009 but in TurboDelphi/BDS2006 I get an error:
[Pascal Error] xxx.pas(117): E2033
Types of actual and formal var
parameters must be identical
...
var
osVerInfo : TOSVersionInfoExW;
i : Integer;
begin
FillChar(osVerInfo, SizeOf(osVerInfo), 0);
osVerInfo.dwOSVersionInfoSize:=SizeOf(TOSVersionInfoExW) ;
if GetVersionExW(osVerInfo) then
...

Seems buggy, but in D2007 (and thus I guess also in D2006) GetVersionExW requires TOSVersionInfoEx as parameter. In D2009 this equals TOSVersionInfoExW, but below D2009 this is equal to TOSVersionInfoExA. You should go well by declaring osVerInfo as TOSVersionInfoEx. This should compile with both versions.

Related

Delphi ZeosLib [Incompatible types: 'TZConnection' and 'TZAbstractConnection']

I have a system in Delphi 7 with zeos 6 in wich i use the following function:
function zIncCodeByYear (zQry : TZquery; ....): String;
var
zConLocal, zConOriginal : TZConnection;
...
begin
bActive := zQry.Active;
zConOriginal := zQry.Connection;
This always worked fine, Now I need to convert this system to Delphi Seatle and, consequently, to Zeos trunk (7.2), after to install this version, in time compile, I get the error:
[dcc32 Error] zeosfuncs.pas(265): E2010 Incompatible types: 'TZConnection' and 'TZAbstractConnection'
What happens? how to get the connection from zquery in this version?
You can simply use ZAbstractConnection and casting to TZConnection does not make a difference for you. Whatever you do is not wrong in this specific case.
With the help of TZConnection a few properties such as Database, Protocol, ... are being published. In the base class TZAbstractConnection those are public.
You haven't really provided much code. But presumably Zeos changed the type of TZQuery.Connection to TZAbstractConnection. So it should suffice for you to change your local variable declaration as follows:
var
zConLocal, zConOriginal : TZAbstractConnection;
And also remember the principle: Program to an interface, not an implementation (Unfortunately the accepted answer on that question is brilliantly amusing, but wrong. At least the answer I linked is correct.)

Using BDE API (BdiCopyTable) with Delphi 10.1 Berlin

The following code compiles and workes using Delphi 5 but not using Delphi 10.1 Berlin;
function CopyTable(const tSource: TwwTable; const Destination: string): DBIResult;
var
pSourceTableName, pDestination: array[0..DBIMAXTBLNAMELEN] of char;
begin
tSource.Open;
StrPCopy(pSourceTableName, tSource.TableName);
StrPCopy(pDestination, Destination);
Result := DbiCopyTable(tSource.DBHandle, False, pSourceTableName, nil, pDestination);
tSource.Close;
end;
Compiler reports [dcc32 Error] SUPPORT1.PAS(3655): E2010 Incompatible types: 'PAnsiChar' and 'array[0..260] of Char' twice.
How do I change it such that it compiles clean and works as intended?
NB. I cannot scrap the BDE at this stage of a large migration.
DbiCopyTable expects AnsiChar, so you should declare both char arrays accordingly.

How to resolve Delphi error: Incompatible types: 'PWideChar' and 'Pointer'

I have this piece of code from Delphi 7:
var
lpRgnData: PRgnData;
PC: PChar;
PR: PRect;
...
PC := #(lpRgnData^.Buffer[0]);
In Delphi XE4 it gives the following compile error:
Incompatible types: 'PWideChar' and 'Pointer'
How should this code be updated to work correctly in XE4?
Thanks
Whether or not this compiles depends upon the setting of the type-checked pointers option. You clearly have enabled that option which is an excellent decision. Doing so results in stricter type checking.
With type-checked pointers disabled, your code does compile. With type-checked pointers enabled, your code does not compile, which is what you want because your code is not valid.
Now, on to the types in question. They are defined in the Windows unit like this:
type
PRgnData = ^TRgnData;
{$EXTERNALSYM _RGNDATA}
_RGNDATA = record
rdh: TRgnDataHeader;
Buffer: array[0..0] of Byte;
Reserved: array[0..2] of Byte;
end;
TRgnData = _RGNDATA;
{$EXTERNALSYM RGNDATA}
RGNDATA = _RGNDATA;
The benefit of using type-checked pointers is that the compiler can tell you that what you are doing is not valid. It knows that lpRgnData^.Buffer[0] has type Byte and so #(lpRgnData^.Buffer[0]) has type ^Byte. And it knows that is not compatible with PChar which is an alias for PWideChar, that is ^WideChar.
Fix your code by changing the type of PC to ^Byte or PByte.

Delphi: Invalid typecast with Move

I am installing an old component pack TSCap32 and get error Invalid typecast in multiple location with Move command.
var
pCopiedDib: PChar;
...
Move(pOrigDibBmi^, TByteArray(pCopiedDib^)[0], BmiSize);
The unit itself declare TByteArray like bellow:
type
TByteArray = array[0..0] of Byte;
How to resolve this error?
The cast that you are using requires that the TByteArray and pCopiedDib^ types have the same size. They do not: TByteArray has size 1, and pCopiedDib^ has size 2. Thus the compiler rejects your code because it is not valid.
The code was presumably originally written for pre-Unicode Delphi where PChar is an alias for PAnsiChar. In that scenario the code compiles. Now, you use a Unicode Delphi and PChar is an alias for PWideChar, and hence the types have different size.
Exactly how to fix your code is unclear. If you define pCopiedDib as PAnsiChar then your code will compile, but whether or not it will work is a different matter altogther. I suggest that you study this code further now that you know the cause of the error.

delphi E2003 undeclared identifier 'self'

I need a bit of help; I'm helping a friend port a Delphi app built years back to newer versions of Windows, as it currently only runs on Windows 95.
The code utilises 3rd party libraries from Woll2Woll for DB operations.
One of these libraries generates the error E2003 Undeclared identifier: 'self'.
I've been through a number of sites via Google and with my limited knowledge of Delphi (stemming from my Pascal training about 12 years ago and extrapolating my slightly rusted PHP, BASH, ColdFusion and ASP coding skills), I've run into a brick wall - I'm strapped for time and can't make sense of the info I'm coming across on the web.
The problematic code segment is from the wwwQuery.pas file and looks like this:
{$ifdef wwDelphi3Up}
procedure TwwQuery.OpenCursor(InfoQuery: Boolean);
{$else}
procedure TwwQuery.OpenCursor;
{$endif}
begin
{$ifdef wwDelphi3Up}
inherited OpenCursor(InfoQuery);
{$else}
inherited OpenCursor;
{$endif}
//Modded by Arie
//wwSaveAnswerTable(self, Handle, FAnswerTable);
wwSaveAnswerTable(self, Handle, 'FAnswerTable');
end;
The precise error messages are:
[DCC Error] wwQuery.pas(243): E2003 Undeclared identifier: 'self'
[DCC Error] wwQuery.pas(244): E2029 '.' expected but ';' found
[DCC Fatal Error] wwcommon.pas(285): F2063 Could not compile used unit 'wwQuery.pas'
Line 243 is the 2nd last line, just above the end;
The wwSaveAnswerTable function looks like this:
Function wwSaveAnswerTable(ADataSet: TDBDataSet; AHandle: HDbiCur; tableName: string): boolean;
What must I change the Self parameter to, to stop the compile error?
Thanks a stack.
The problem is related to compiler define wwDelphi3Up or any related up in code.
As you see next error message: [DCC Error] wwQuery.pas(244): E2029 '.' expected but ';' found
Compiler expects end of program, and line wwSaveAnswerTable(self, Handle, 'FAnswerTable'); are not compiled inside OpenCursor method. That's why Self is not defined.
You don't need to change parameter, because for sure will affect functionality.
Try to compile it without defines, if you are not use an ancient version of Delphi:
procedure TwwQuery.OpenCursor(InfoQuery: Boolean);
begin
inherited OpenCursor(InfoQuery);
wwSaveAnswerTable(self, Handle, 'FAnswerTable'); // Here prob FAnswerTable without quotes
end;

Resources