Jump to content

All Activity

This stream auto-updates     

  1. Yesterday
  2. dummzeuch

    Avoid parameter evaluation

    Yes, some special characters plus if plus ifend are a lot more convenient than an if then statement. I'm sold.
  3. Remy Lebeau

    Avoid parameter evaluation

    Not quite. You have implemented DoProcess() incorrectly, causing undefined behavior. The code compiles, but it will not behave correctly at runtime for certain types. For instance, try passing a single Char into it and your code will crash. That approach is wrong. You cannot treat all of those types the same way, as they are stored in different ways in the array. vtChar and ctWideChar are stored as individual values in the array itself (like integers are), whereas vtString is a pointer to a ShortString variable, whereas vtAnsiString and vtUnicodeString are copies of the data block pointer from inside of an AnsiString/UnicodeString instance, etc. You need to handle the various types individually and correctly, eg: procedure DoProcess(const Args: array of const); var i: Integer; begin for i := Low(Args) to High(Args) do begin case Args[i].VType of vtString: Writeln(Args[i].VString^); vtChar: Writeln(Args[i].VChar); vtPChar: Writeln(Args[i].VPChar); vtWideChar: Writeln(Args[i].VWideChar); vtPWideChar: Writeln(Args[i].VPWideChar); vtAnsiString: Writeln(AnsiString(Args[i].VAnsiString)); vtWideString: Writeln(WideString(Args[i].VWideString)); vtUnicodeString: Writeln(UnicodeString(Args[i].VUnicodeString)); vtInteger: Writeln(Args[i].VInteger); vtInt64: Writeln(Int64(Args[i].VInt64)); else Writeln('Type handling not implemented yet ' + IntToStr(Args[i].VType)); end; end; end; Also, see the MakeStr() example in this earlier post:
  4. You don't. Use a TPaintbox as a drawing surface, it has a Canvas and an OnClick event. TImage is another candidate, it contains (by default) a bitmap you can draw on using the image component's Canvas, and it also has an OnClick event. As explained in other replies a TCanvas is just a wrapper for a window's device context, it cannot receive mouse events directly.
  5. Morgan Christen

    Delphi 12 - Action Bar Menu painting issues with RDS

    My VPS clients reported flickering, which I have cured withe the following code: // Fix RDP flickering in Delphi 12 if application.InRemoteSession then if application.SingleBufferingInRemoteSessions then application.SingleBufferingInRemoteSessions := false; I apologise for not recording the source of this tip in the comment. I have since discovered that the progress bars from some 3rd parties I use are no longer refreshing as they should. 100% but not quit 100% :0)
  6. Well, as Francois said it, and i will elaborate a little on that. TCanvas is Delphi/Pascal RTL encapsulation for Device Context: https://learn.microsoft.com/en-us/windows/win32/gdi/device-contexts https://learn.microsoft.com/en-us/windows/win32/gdi/about-device-contexts These are Output devices and has no Input, and by Input i mean there is no hardware user input or interaction, their input is solemnly comes from drawing APIs, and in other words they are GDI drawing object that simulate a painting canvas (real life canvas) to be processed further, like to be rendered on monitor or to be passed to printer.... they are build that way to unify User mode GDI and supply one Interface to different hardware, their functionalities differ based on what the hardware and its driver support, while the interface is the same for them all.
  7. Vandrovnik

    Avoid parameter evaluation

    If log level is defined in compile time, he could also use $IFDEF or $IF instead 😄
  8. TCanvas is a kind of API for a drawing surface. It encapsulate drawing primitives like line or text. A TCanvas is a property of some other graphics component, for example an image component. This is at that component level that you must handle onClick. This being said, you should better explain what you need and what you already have, preferable with some code sample. If you explain correctly, chaces are that you get a helpful answers.
  9. dummzeuch

    Avoid parameter evaluation

    It's cumbersome to have that if statement all the time.
  10. Lajos Juhász

    Add onClick event on TCanvas

    you cannot do add a property to a class that doesn't have it.
  11. Only one problem. Image1 has onClick event by default. TCanvas does not have it. So I need to add property I think. Its a little bit more complicated.
  12. Lajos Juhász

    Add onClick event on TCanvas

    It is TNotifyEvent = procedure(Sender: TObject) of object; To assign a value OnClick event you have to create a method with this signature. For example: type TForm1 = class(TForm) Image1: TImage; procedure FormCreate(Sender: TObject); procedure DoSomethingClick(Sender: TObject); // Event handler for an OnClick private { Private declarations } public { Public declarations } end; Then you can write in your code: procedure TForm1.FormCreate(Sender: TObject); begin Image1.OnClick:=DoSomethingClick; end;
  13. Hello, I have TCanvas and I want to dynamically add onClick event. How do I do that? I read something about TNotify and adding property, but how exactly? Need whole code.
  14. FreeDelphiPascal

    Devin AI - Is it already happening?

    I hope (at least in EU) they will introduce some regulations around AIs.
  15. Celebr0

    Each .py script in a separate window

    Hello, look what I need to achieve, I can run one .py script in at least 10 console windows at the same time, but I can’t achieve this through Python4Delphi with GIL locking only one running .py script works at a time
  16. timfrost

    Avoid parameter evaluation

    I cannot believe how complex this discussion has become! All to avoid having a tiny unit with four boolean variables defined in the interface, along with a GetLogLevel function which can be called when needed, and then writing, for example: if LOGINFO then log(MyComplexStringExpression); if LOGALL then Log(AnotherExpression); This seems to meet all the criteria of readability, simplicity and efficiency.
  17. Lajos Juhász

    Devin AI - Is it already happening?

    Microsoft might or might not using Github for train AI. How can you be sure that when you send with a prompt a piece of code it is not going to be used for training the AI system. If that code contain some top secret detail. The owner of the source code could sue the developer. (I daily work on code bases that is owned by a client of the company I am working for)
  18. Kas Ob.

    Avoid parameter evaluation

    Can't shake it off without trying to validate the type, so here what i tried and it is working perfectly {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; procedure DoProcess(const Args: array of const); var i, Count: Integer; begin Count := Length(Args); if Count > 0 then for i := 0 to Pred(Count) do begin case Integer(Args[i].VType) of vtString, vtChar, vtWideChar, vtAnsiString, vtWideString, vtUnicodeString: Writeln(string(Args[i].VString)); vtInteger: Writeln(Args[i].VInteger); vtInt64: Writeln(Int64(Args[i].VInt64)); else Writeln('Type handling not implemented yet ' + IntToStr(Args[i].VType)); end; end; end; procedure Test; var st: string; begin st := 'Param1'; DoProcess([st, 'Param2', 5]); end; begin Test; Readln; end. output The generated assembly is nice and short, one thing though, don't forget to declare Args itself as const as in procedure DoProcess(const Args: array of const) or it will be copied locally, in other words it will be ugly.
  19. Hi, I found out that my routine above is working as planned, but its important to use the same mainModule.variable names 🙂 . Sorry for the confusion, hope the code helps someone. Cor
  20. Kas Ob.

    Avoid parameter evaluation

    I never thought about this. Thank you !
  21. Joseph MItzen

    Devin AI - Is it already happening?

    It all depends on the implementation. I believe JetBrains is offering their own LLM service in their IDEs now, but they've also added a completely local LLM that can perform whole-line auto completion. If hypothetically Embarcadero was offering their own LLM service, it could be turned on by default and people might not be happy about that. But I agree, as an excuse it seems a bit flimsy. I'm not sure why waiting longer would somehow lead to anything being more secure by design.
  22. corneliusdavid

    Devin AI - Is it already happening?

    I don't understand why this would be a concern. Certainly, any AI built in would just be an interface to utilize your own AI account somewhere, right? Nothing would get automatically uploaded unless you hook it up and start using it. Just like Delphi has integration for git but you don't have to use git inside the IDE unless you tell it to and give it your account information. Am I missing something?
  23. corneliusdavid

    What is the best AI at Delphi

    It was interesting seeing this list and the responses as I've only used the free ChatGPT about a half dozen times--I haven't considered getting into it seriously. But I decided I should look through these tools listed here (didn't know there were so many geared for programming!) and get up to speed since AI is here and being used and talked about everywhere these days--I'm starting to see how this could be quite a time-saver for many things. Today, I was struggling with some untyped string parameters being passed into a function and it was failing to get the values properly after converting this old code from Delphi 5 to Delphi 12. I knew I had to add support for UnicodeCode types but I was struggling with how to get the value from the embedded pointer. I asked ChatGPT and it gave a pretty good answer--and it was correct but it only listed the new Unicode and WideString types. I wanted to be able to support ShortString as well. So, I posed the exact same question to Claude and it gave a nearly identical answer BUT included support for ShortString as well, noting the slightly different syntax (you have to dereference it while you don't with the new modern string types). I asked Claude about the difference and it gave a good answer about the history of string types and why ShortString has to be handled differently. I'm very impressed and am about ready to sign up for Claude! (I like what I'm reading about it's "project" feature as well.) Thanks all for your comments!
  24. Last week
  25. hsauro

    Devin AI - Is it already happening?

    It does more than trivial code. Even with trivial code, if it a long bit of trivial code, the AI is a time saver.
  26. afturk

    Delphi 12: MessageDlg doesn't show icons

    Thanks, I misunderstood the situation. It works fine Thank you very much
  27. Remy Lebeau

    Avoid parameter evaluation

    Since performance is in question, I would suggest taking this approach a step further and use 'array of const' instead of 'array of string'. That way, you can pass in integers and other fundamental types as-is and not invoke the overhead of converting them to strings unless you are sure you actually need to, eg: procedure Log(LogLevel: TLogLevel; const Args: array of const); overload; begin if CanLog(LogLevel) then begin // convert Args to a log message and write it out as needed... end; end; Log(llTrace, ['Test', GetLastError(), ...]);
  1. Load more activity
×