dummzeuch 1505 Posted December 4, 2020 The unit Windows declares quite a few rather generic identifiers, e.g. const ERROR = 0 which is annoying when you want to use that identifier for a local variable (e.g. a string): var Value: Double; begin // function TryGetSomeValue(const _Name: string; out _Value: Double; out _Error: string): boolean; if not TryGetSomeValue('WrongName', Value, Error) then begin LogError(Error); Value := -1; end; This will not compile because Error is a constant and not a string variable. So I want to declare it as a local string variable using Shift+Ctrl+V but that fails (does nothing *1) because there is already such an identifier. This is no problem when it occurs once, but it becomes a bloody nuisance when you have to write several similar function calls. I would really like to use "Error" as a variable name here, rather than "Err" or "lError" or "ErrorStr". Is there any way to undeclare an identifier, so Shift+Ctrl+V (and probably others) work again? I doubt it but I have been wrong before. (*1: Yes, one could regard this as a bug in the refactoring functionality. I haven't checked whether there already is a bug report.) Share this post Link to post
David Heffernan 2345 Posted December 4, 2020 30 minutes ago, dummzeuch said: Is there any way to undeclare an identifier, so Shift+Ctrl+V (and probably others) work again? No Share this post Link to post
Arnaud Bouchez 407 Posted December 4, 2020 (edited) I guess the only way is to use a "free" name like "ErrorMsg" instead of "Error"... Edited December 4, 2020 by Arnaud Bouchez Share this post Link to post
Guest Posted December 4, 2020 (edited) not talk about that "Error" is procedure in System.pas, line 5759. RAD Studio 10.3.3 Arch! if using a .INC for easy hide "original type"? A FranksteinBuilders presents: 😂 INCLUDE FILE {$DEFINE ERRORasSTRING} // {$IFDEF ERRORasSTRING} var Error: string; {$ELSE} // Else, stay the original "Const" {$ENDIF} in USE: unit Unit1; interface // uses // ...; {$I incRedeclareErrorForMyProject.inc } // var Error:string; // type // ... // var // Error: string; procedure prcTestUnit2; implementation { ..$I incRedeclareErrorForMyProject.inc } // var // Error: string; procedure prcTestUnit2; var lText: string; begin lText := Error; // // System.Error( errorCode:TRuntimeError ); end; end. of course, if "ERRORasSTRING" not defined, then, the compile help you with many "Error"s hug Edited December 4, 2020 by Guest Share this post Link to post
Guest Posted December 4, 2020 look this when asking "help" for Ctrl+Shif+V procedure: Share this post Link to post
Rollo62 536 Posted December 5, 2020 (edited) I know its modern nowadays to use all kind of bare names for anything. But those names are very likely to conflict with identifiers, keywords, etc., with a whole bunch of possible hard.-to-find sideeffects. Thats why I still like consequently use the decoration of names: L - for local instance: LError F - for field instance: FError G - for a global instance: GError (nevertheless: global variables are not recommended) This little extra char gives me a lot of extra-info - its not a function or procedure, if you use it with discipline - its not a global, intrinsic function, if you use it with discipline - its a local or field instance, or even global All this just because of the tiny character, I think its still very much worth it. Edited December 5, 2020 by Rollo62 Share this post Link to post
Guest Posted December 5, 2020 (edited) I like: "lMyXXXXXX" l=L because ALL is "local" on the end! Global = local for my app (or project) Local = local for my unit/proc/func When "XXXX" have a reference with type of var, ex.: lMyFDClient = FDQuery/Table client then, "l" on the start it's good for me! Edited December 5, 2020 by Guest Share this post Link to post
Guest Posted December 5, 2020 another way, as was said in another post, is possible use "&" char before names on vars, like: var &Error: string; procedure TForm1.FormCreate(Sender: TObject); begin Caption := &Error; end; NOTE: verify since when it's possible in Delphi editions! Share this post Link to post
Rollo62 536 Posted December 7, 2020 (edited) On 12/5/2020 at 4:58 PM, emailx45 said: another way, as was said in another post, is possible use "&" char before names on vars, like: var &Error: string; procedure TForm1.FormCreate(Sender: TObject); begin Caption := &Error; end; Yes, thats possible too, and I always wonder why on earth I should ever do it like that ? Oh yeah: Its so much advanced over FError, to have a fancy pig-tail in front Edited December 7, 2020 by Rollo62 Share this post Link to post
Guest Posted December 7, 2020 (edited) "F" is for private "Field" on Class/Record/Interfaces etc... definitions, not for common "var" on unit-body by default. each other use a "fancy pig-tail" that like it Edited December 7, 2020 by Guest Share this post Link to post