Why doesn't the new compiler recognize "NULL" in this old code? - delphi

I just downloaded the ADSI and it seems to be that it is not compatible with Delphi Embarcadero XE4.
When I try to compile one of the examples, I get this error:
[dcc32 Error] adshlp.pas(128): E2003 Undeclared identifier: 'NULL'
And this is the line:
varArr := NULL;
What's wrong?

Null used to be declared in the System unit, so it was available globally. In Delphi 6, all Variant-related code moved out of that unit and into the new Variants unit. Since Null is a function that returns a Variant, Null was included in the move, so it is no longer available implicitly.
To fix the old code, simply add Variants to your uses clause in any unit that needs it:
uses ..., Variants;

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.)

Delphi - disable controls not working EMS Advanced Export 4

I tried to disable ABSQuery1 controls before exporting data :
procedure TForm1.QExport4Dialog1BeforeExportRow(Sender: TQExport4;
Row: TQExportRow; var Accept: Boolean);
begin
ABSQuery1.DisableControls;
end;
But I get :
> [dcc32 Error] Unit1.pas(75): E2003 Undeclared identifier: 'TQExport4'
> [dcc32 Error] Unit1.pas(76): E2003 Undeclared identifier:
> 'TQExportRow' [dcc32 Error] Unit1.pas(204): E2005 'TQExport4' is not a
> type identifier [dcc32 Error] Unit1.pas(205): E2005 'TQExportRow' is
> not a type identifier [dcc32 Fatal Error] Project1.dpr(15): F2063
> Could not compile used unit 'Unit1.pas'
What am I doing wrong ?
Your error messages all indicate that you have not used the units in which the named symbols are declared. Add those units, those that declare TQExport4 and TQExportRow, to the uses clause of your Unit1.
It's usually worth consulting the documentation when you encounter a compiler error that you do not understand. Search for the error code, for example E2003. The documentation says:
The compiler could not find the given identifier - most likely it has been misspelled either at the point of declaration or the point of use. It might be from another unit that has not mentioned a uses clause.
The final sentence covers your scenario, although the author got in a tangle when writing that text and the words don't make a lot of sense. Sigh.
Incidentally, the example at the bottom of that documentation page made me sad. The author indicates a preference, when correcting mis-named variables, for the option requiring the fewest key strokes. Never mind getting the name right, just make it compile with the fewest key strokes and who cares about the next person to read the code. Pah!

delphi 2006, SynTaskDialog compilation error in custom component

i am working on component for delphi 7 and delphi 2006, the component uses SynTaskDialog.pas from synopse, i have successfully used the SynTaskDialog.pas in delphi 7 component, but when i try to use it in delphi 2006 to create a component package. i get an error
i have found a solution for the same on synopse.info/forum
Quote:
I've found two workarounds: Either
replace the pointer arrays with string arrays like
TD_ICONS_IDENT: array[TTaskDialogIcon] of string =(
'', SMsgDlgWarning, SMsgDlgConfirm, SMsgDlgError, SMsgDlgInformation,
'', SMsgDlgInformation);
and remove some LoadResString calls or
2.replace the pointer arrays with functions like
GetIconIdent(TTaskDialogIcon): Pointer
but even after that i cannot compile the package for the component. and these errors come
[Pascal Error] E2201 Need imported data reference ($G) to access 'SMsgDlgOK' from unit 'SynTaskDialog'
[Pascal Error] E2201 Need imported data reference ($G) to access 'SMsgDlgYes' from unit 'SynTaskDialog'
[Pascal Error] E2201 Need imported data reference ($G) to access 'SMsgDlgNo' from unit 'SynTaskDialog'
[Pascal Error] E2201 Need imported data reference ($G) to access 'SMsgDlgCancel' from unit 'SynTaskDialog'
[Pascal Error] E2201 Need imported data reference ($G) to access 'SMsgDlgRetry' from unit 'SynTaskDialog'
[Pascal Error] E2201 Need imported data reference ($G) to access 'SCloseButton' from unit 'SynTaskDialog'
Why didn't you ask the question of the project forum?
A solution may enhance the official code of this Open Source unit.
OK - it may help me gain some SO points. ;)
AFAIK this "E2001" issue has already been identified - see this post and should have been fixed in the latest trunk. This is what sounds to work with Delphi 7, but not with Delphi 2006.
Here is a potential workaround of this compiler bug:
Define such a function:
function IconMessage(Icon: TTaskDialogIcon): string;
begin
case Icon of
tiWarning: result := SMsgDlgWarning;
tiQuestion: result := SMsgDlgConfirm;
tiError: result := SMsgDlgError;
tiInformation, tiShield: result := SMsgDlgInformation;
else result := '';
end;
end;
To be used as such:
if Inst='' then
Inst := IconMessage(aDialogIcon);
This is now committed in the project trunk.
Thanks for using our Open Source component!

Why can't I use a resourcestring as a constant?

I've downloaded embtvstools (Embarcadero TVirtualShellTools) from: http://embtvstools.svn.sourceforge.net/
However when I create a new package, drop the .pas files (and a missing compilers.inc from VirtualTreeView in) and compile the lot, I get an error E2026, why is this and how do I avoid/workaround this?
resourcestring
sAssociationChanged = 'Association Changed';
sItemCreate = 'Item Create';
sItemDelete = 'Item Delete';
....
const
// Literal translations of TShellNotifyEvent type. Useful when using the
// OnShellNotify event to print out what event occurred. VirtualShellUtilities.pas
// has a helper function ShellNotifyEventToStr that uses these.
VET_NOTIFY_EVENTS: array[0..19] of WideString = (
sAssociationChanged,
sAttributes,
sItemCreate,
.....
[Pascal Error] IDEVirtualResources.pas(155): E2026 Constant expression expected
[Pascal Error] IDEVirtualResources.pas(156): E2026 Constant expression expected
[Pascal Error] IDEVirtualResources.pas(157): E2026 Constant expression expected
Update
Changing the widestring to a string stops the compiler complaining, (I suspect it will create some issue elsewhere because widestring <> string) I would like to keep the constant of type widestring.
As Uwe points out in the comments, resourcestring in Unicode versions of Delphi is of type WideString. But you are using pre-Unicode Delphi and so resourcestring is simply AnsiString. This explains the compilation error.
How to proceed depends on what you are attempting to do. If you intend to translate these strings into different languages then you may be in a bind. If you are intending to do that then you would obviously be far better off with a Unicode version of Delphi.
So, since you are sticking with a pre-Unicode Delphi I guess you don't actually need to translate the strings. In which case just change the declaration of the const array from WideString to string. As it happens, this array is declared by this code but never once referred to.

GetVersionExW error in BDS2006

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.

Resources