Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 08/14/24 in Posts

  1. Dalija Prasnikar

    ifthen strange return value !

    I would suggest that you don't use ChatGPT or any other AI for writing or explaining the code. While it may give you correct results at times, quite often it will be completely wrong and you will have no idea whether what it said is correct or not.
  2. Dalija Prasnikar

    ifthen strange return value !

    Er... no. It does not matter how correct is the input, the output can still be outmost garbage when it comes to the correctness, it will just sound nice. Also, if you don't know whether some statement is correct or not how can you verify the output. For instance AI can say "Local variables are automatically initialized" and "Local variables are not automatically initialized" If you don't know which of those statements is true, you will not be in position to verify. You cannot even check with code, because local variable can accidentally occupy memory that was zero at the time, so it may seem like the first statement is true, while it is not. It does not matter how often it is correct (the best AI will be wrong in over 20% of responses, which is far from insignificant), it is about inability of a person who does not know something to determine whether response is correct or not. Even merely translating and rewording of correct content can result with incorrect output. Some examples how AI can lie to you: https://github.com/mdn/yari/issues/9208 and MS copilot demonstration video around 38 minutes.
  3. corneliusdavid

    ifthen strange return value !

    There are two allocations for memory you're dealing with: LObj is a pointer to an object. That pointer takes up space in memory and is allocated in your VAR declaration section as soon as that procedure is called. If it's not specifically initialized with either nil or a pointer to an actual object, the value of that pointer will contain whatever happened to be in that memory location. The second memory allocation happens when the statement LObj := TMyClass.Create; is called. That allocates memory for the object type TMyClass and the pointer to that memory space is stored in the LObj pointer variable. So when you say "LObj is just a variable..." you're right but you might be forgetting what that means: it's a variable at a memory location and in this case, it's a pointer variable that doesn't yet know what it's pointing at. Another way to look at it is if you declared this in your VAR section: var X: Integer X is a variable just like LObj is in that it's allocated when the procedure is called and similarly, if you don't assign X a value, you'll end up with whatever value happens to be in that memory space. Can you imagine testing the value of X without first assigning a number to it?
  4. corneliusdavid

    ifthen strange return value !

    When you compiled, you likely got the following warning: [dcc32 Warning] Main.View.pas(54): W1036 Variable 'LObj' might not have been initialized You should always take special notice to eliminate warnings in your code.
  5. Stefan Glienke

    GExperts for Delphi 10.4.1

    get the source from SourceForge open Projects\DelphiXx120\GExpertsRS120.dproj compile run Binaries\Register-GExperts-XX120.cmd restart IDE
  6. i ask GPT for a good Example and gives me this: procedure TMainView.Btn_1Click(Sender: TObject); var LObj: TMyClass; // Declare a local variable of reference type begin // At this point, LObj is just a pointer, and it hasn't been assigned to any object yet. ShowMessage(IntToStr(Integer(LObj))); // This may show some random (garbage) value LObj := TMyClass.Create; // Now, LObj points to a new instance of TMyClass allocated on the heap. ShowMessage(IntToStr(Integer(LObj))); // This will show the actual memory address of the object instance // When you’re done, free the object to avoid memory leaks. LObj.Free; end; Explanation LObj Declaration: LObj is declared as a variable of type TMyClass. This is a reference type, which means LObj is just a pointer (an address) that will eventually point to an object instance. Memory Allocation: LObj itself is a local variable, so it is allocated on the stack. However, the object instance that LObj will point to is allocated on the heap when you create it using TMyClass.Create. Garbage Value: When LObj is declared, it hasn't been initialized to point to anything. The memory allocated on the stack for LObj might contain whatever data was there before, which is why ShowMessage(IntToStr(Integer(LObj))) might display a random (garbage) value. This is because stack memory isn't automatically cleared. Object Creation: When you create a new instance of TMyClass with LObj := TMyClass.Create;, the memory for this instance is allocated on the heap. LObj now holds the memory address of this instance. Managed Types: Only managed types (e.g., strings, dynamic arrays, interfaces) are automatically initialized to nil or equivalent values when declared. Since LObj is not a managed type, it can hold any value until you explicitly initialize it by creating an object. Key Takeaways Uninitialized Pointers: If you don't initialize a reference type variable (like LObj), it might contain a garbage value that points to an undefined memory location. Memory Allocation: Local variables are allocated on the stack, but the actual object instances they point to are allocated on the heap. Automatic Initialization: Only managed types are automatically initialized to nil or similar default values when declared. This example illustrates the importance of initializing your reference variables to nil or creating an object before using them to avoid unexpected behavior. ---- I have a much clearer understanding of the entire process now. Thank you, everyone!
  7. Dalija Prasnikar

    ifthen strange return value !

    It doesn't work like that. LObj is reference type. That means it consists of two parts. LObj variable itself is merely a pointer (address) that will point to the object instance when it is allocated on a heap. All local variables are allocated on stack, not heap. So when you declare local variable the memory for the pointer is automatically allocated on stack when FormCreate is called. Stack memory is not automatically cleared, so whatever values were there, they will remain. Only managed types local variables will be automatically initialized. When you create object and assign it to that variable then created instance will be allocated on a heap and address of that memory location will be stored in LObj variable. This behavior is same on all platforms. However, until Delphi 10.4 Delphi mobile platforms had ARC compiler where objects were automatically managed and local object variables were automatically initialized on those platforms.
  8. I think those (uses-feature) are just play store hints? The application won't be offered to devices without the uses features that are marked as required. They don't seem to be used by the android loader itself. Might be the OS is trying to be clever and attempting to pre-load/integrate something related to a uses-feature that then causes issues or a crash.
  9. i agree with you @Rollo62 on this term, we should be the first to ask a good questions to get a good answers with best accuracy of the truth .. By the way, the answer from ChatGPT above would have been impossible without the question being, in reality, the answer from the highly respected and dear-to-my-heart @Dalija Prasnikar. If you take a closer look at what ChatGPT provided above, you’ll notice that it did a wonderful job of summarize, re-format and complete ., and beautifully elaborating on the esteemed professor Dalija Prasnikar's response.. The above post from ChatGPT 4.o is the best proof of what you say. --- finally , I want to thank you all once again for your amazing and enthusiastic contributions. Your accuracy in providing information has really helped me understand and sum up a journey that many people might still be struggling with.
  10. Well, my reference is always the ChatGPT 4o, while all my experiments with M$ Copilot or Bing or whatever from Microsoft was never working acceptable for me. Ok, I admit you can have bad AI and better AI. CGPT, Sonnet are quite acceptable in their latest incarnations, perhaps others too. At least from my practical experience, the ChatGPT 4o output is very reliable for all sorts of tasks, of course I try to help AI as best as I can by producing reasonable prompts. In re-formatting it's much better than 20% failure rate, I would guess by gut feeling, I would say 2-5% failure in my workflows.
  11. If you provide GPT with the correct results and all necessary information bits it needs, it can produce a very good explanation in a very precise natural language, even if the original explanations were spelled too lazy or informal. Especially in this category of natural language it works very well, to produce very precise desciptions of known facts and sources. You are right, that you still need to check this output well, but that is always the case with todays AI. The chance of AI hallucination is quite low, if you give it an already predefined, correct text pattern, that just needs to be summarized, re-formatted and completed. In fact I have never seen any hallucination from at least ChatGPT 4, when it comes to these tasks and proper input prompt.
  12. A small correction for this GPT answer: Not every local variable is allocated on the stack, so LObj could be on the stack, or due to optimization have a dedicated CPU register to use. In other words, LObj is either on the stack or in a register, but the result will be the same, the stack might hold data (Value) previously been written (or zero if the stack is never being reached before at this depth), and a register will have a Value from the last usage being from this procedure/function or a previous one. Delphi compiler is less optimized for this registers usage (optimization) for local variable then FPC and less than most other languages compilers, yet it does it sometimes.
  13. Cristian Peța

    ifthen strange return value !

    Not. The best practice is to initialize to nil if you need this. Because there was something before and that memory was deallocated. It doesn't have anything with object allocation. You can allocate the memory for an object and you variable will remain as it was. var LObj: TObject; begin TMyClass.Create; //LObj is not changed and will contain garbage Only if you pass the value of the object to the variable: LObj := TMyClass.Create; Not. Declaration will only allocate the memory for the variable (a typed pointer in this case) and that memory will contain garbage.
  14. corneliusdavid

    ifthen strange return value !

    Because LObj is not initialized to nil; therefore, it gets whatever happens to be in memory. Assigned() simply checks to see if the pointer is 0; when I ran it in Delphi 12.1, and put a break-point at the label assignment, LObj was -1 ($FFFFFFFF).
  15. Dalija Prasnikar

    ifthen strange return value !

    LObj is local variable and it is not initialized. That means it will hold some random value (garbage). This is why it can show that object is allocated when it is actually not. You need to initialize it (to nil, or assign some object instance to it) before you can call your function.
  16. pyscripter

    TSynEdit - Custom Highlighter

    - Update your SynEdit to the latest version from TurboPack/SynEdit: SynEdit is a syntax highlighting edit control, not based on the Windows common controls. (github.com) - Look at the SynGen folder. The file Highlighters-HowTo.htm explains the basic steps. You need to create a grammar file and then SynGen.exe will generate your highlighter.
×