Jump to content

PeterBelow

Members
  • Content Count

    562
  • Joined

  • Last visited

  • Days Won

    13

Posts posted by PeterBelow


  1. 2 hours ago, SneakyPeaky99 said:

    Thank you for advice, i have managed to determine where was the problem with 'Extension already exists' exception. I have one more question, do you know any way to solve errors like: "Runtime error 204 at 0027BE19"? Or do you know any place i should start looking for solution? Code on the right side is an address code given in hex but it doesn't give me any clue what is going on.

    errorpng.png

    See the list of error codes here. 204 is an invalid pointer operation, which may be caused by corrupted memory (stack overwrite, writing beyond the bounds of a heap-based memory block, etc.).

    Open the project in the IDE, place a breakpoint on the first code line after the "begin" of the DPR file, run under the debugger until you hit this breakpoint. If the error pops up before you reach the breakpoint it is triggered by code executed from a unit initialization section. In this case build with debug dcus and place a breakpoint on the first line of the initialization section of system.sysutils.

    After you reach such a breakpoint you can use the "go to address" function of the debugger. This hides in the context menu of the disassembly view (View -> Debug windows -> CPU Windows). Make sure you have "debug information" selected in the active project configuration. When you type in the address do not forget to start with a "$" sign to flag the typed text as a hex value.

     


  2. 16 hours ago, alogrep said:

    However, I like to print a small logo (saved as abitmap separately) at the sart of the printing, followed by the richedit content, all on the same page.. Is that possible?

    Certainly. You can mix direct output to the printer canvas with rendering via EM_FORMATRANGE.  By the way: do you know Code News Fast? It is an excellent source for Delphi code examples and it even has all the content of the long defunct Delphi newsgroups on hand. This old post may be a good starting point.

     

    By the way: the change in behaviour of your printing code from XE to Delphi 11 may be due to the fact that D11 uses a different version of the richedit common control (4.x) than XE did (2.x). There are suptle differences between these control versions.


  3. 16 hours ago, alogrep said:

    Thanks Peter.

    I applied your suggestions (I did not have the Newpage, because this richedit text will never exceed 1 page).

    However, checking if nextchar <=fmtRange.chrg.cpMin allows me to abort printing but it does not tell me what is the error, why that happens.

    If your text fits into one page it may simply indicate that all text has been printed....


  4. First thing to do is to get rid of the with statement. That just confuses things. Be explicit, use Printer.Canvas.Handle instead of just Handle. And do you ever start a new page? I do not see a Printer.NewPage in your loop.

     

    If I look at the C example code here  nextchar <= fmtRange.chrg.cpMin is possible and should be handled as an error.

     


  5. 3 hours ago, alogrep said:

    Uwe

    that "the vast majority had no problems with this update" is of no sonsolation to me. Now it has become completely unworkable.

    It freezes all the time, with no apparent pattern.

    I had a few problems with freezeups or slowdown with 11.3 but they all went away after I deleted all entries for design-time packes related to refactoring and the welcome page (which I never used anyway) from the registry under HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\22.0\Known IDE Packages.


  6. 4 hours ago, CoMPi74 said:

    Hi there,

     

    I'm struggling with the problem for several hours and I can't solve it.

    Can anyone enlighten me? What have I missed? 

     

    PS. I forgot to mention, I use Delphi XE4. Yes, I know, it's a bit old 😉 

    An event reference you need for SetMethodProp is not a simple method address, it is a record of type TMethod, which holds a pair of pointers, the first (Code) is the address of the method and the second (Data) is the address of the class holding the method. You have to construct the value to pass like this, a typecast as you tried does not quite work for some reason:

     

    function TMyForm.CreateControl(AClass: TControlClass): TControl;
    var
      LEvent: TMethod;
      procedure SetEvent(const aEventName: string; aMethodAdr: Pointer);
      begin
        if IsPublishedProp(Result, aEventName) then begin
          LEvent.Code := aMethodAdr;
          SetMethodProp(Result, aEventName, LEvent);
        end;
      end;
    begin
      Result := AClass.Create(Self);
      Result.Parent := Self;
      LEvent.Data := self;
    
      SetEvent('OnClick', @DoOnClick);
      SetEvent('OnKeyDown', @DoOnKeyDown);
      [...]
    end;

     


  7. On 6/11/2023 at 5:51 PM, Jeff Steinkamp said:

    On my form I have 2 radio buttons and 3 check boxes.  If I change the font of the parent, the font of the control does change, but the foreground color remains black, both design time and runtime.  I do have the ParentFont and ParentColor properties set to true.  I have even attempted to change the font color of the individual component at runtime and they still remain black.  The behavior I would expect is the component font properties would inherit from the parent.

     

    Is this a bug, or do I have something set incorrectly in the IDE?

    See if the controls you use have a StyleElements property showing in the Object Inspector. This allows you to switch off styling for certain UI elements on a per control basis.


  8. 1 hour ago, Analyste2023 said:

    hello Delphi geniuses, I hope you are well, I have a problem, how to filter the data between two dates, i.e. the user wants to display only the data from 06/01/2023 to 06/30/2023 for example, thank you for your help

     

    No data to provide any help on, sorry. We need more detail. If your UI view is populated from a database query just use an appropriate condition in the WHERE clause of the query. Most database engines support the BETWEEN operator for dates; just make sure to formulate the bounds using parameters and not date literals (which are sensitive to date formats, locales for client and server, great potential to cause a mess).

    • Like 1

  9. 3 hours ago, Andrew Spencer said:

    Why can I set the Font.Color property, in Delphi 7, for controls like TCheckBox (and descendents TDBCheckBox etc) TRadioGroup and get the expected result. But in Delphi 10.4.2 everything remains clWindowText (or clBlack).

     

    TLabel.Font.Color works, but most other controls do not.

     

    Have I really just not noticed this for the past few years!?

    This is the style support at work. You can disable/override it on a control basis using the StyleElements property.


  10. The classical way to implement plugins in Delphi is to create packages for the plugins (run-time packages) for which the host app looks in a folder defined in the app's settings or hardcoded to a subfolder of the folder the app itself (the exe) is located in. At startup the app looks for packages (bpl files) in this plugin folder and loads each one in turn via LoadPackage. The package then registers its plugin class in a unit initialization section, for which it calls a method of a class registry singleton object that is implemented in another package that both the app and the plugin packages use (static link). The app then builds the plugin menu from the list of registered plugins. It can also offer an API through such a shared package to allow the plugins to access the host app UI (like the IDE OpenTools API).

     

    This is basically the same design the RAD Studio IDE itself uses to load components. The main drawback is that you need to build the app itself with run-time packages for the run-time library and the VCL (or FMX if you use that for the UI). This makes sure app and plugins use the same memory manager and other RTL and VCL/FMX classes but it complicates distribution of the app, since you also need to distribute the required run-time packages. It gets worse if you use 3rd-party components in app and plugins since you also need to install the  run-time packages for those. Any class to be shared between host app and plugins has to be implemented in a run-time package this way. 

     

    With this design you do not need to change the host app to make it use a new plugin, just copy the new plugin package to the app's plugin folder and it will be loaded on next app start.


  11. 9 hours ago, robertjohns said:

    I am creating a Form1 and freeing it after some time

     

    Now I am trying to check if Form1 is created then create Form2

     

    If Assigned(Form1) then

    Application.CreateForm(TForm2, Form2);

     

    But It does not seems to work any suggestion

    Depends on where you do this check and where you free the form1. If you let the IDE autocreate the forms you add to the project then the first form you add will become the main form and closing it will terminate the application. If you need to show some form before the main form is created you have to edit the project DPR file. The typical scenario is a login form shown before the main form is even created. The DPR file then has to look like this:

     

    uses
      ... list of data module and form units
    {$R *.res}
    
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      ... Application.CreateForm calls for datamodules the login
          form may need
      if TLoginForm.Execute then 
      begin 
        Application.CreateForm(TMainForm, MainForm);
        ... more CreateForm statements for autocreated stuff
        Application.Run;
      end; 
    end.
    
      

    TLoginForm is not autocreated, the Execute method is a public class method that internally creates an instance of the form and shows it modally, then gets any required user input from the form and stores it elsewhere if needed (e.g. in a datamodule or settings store). The Execute method is a function returning a boolean that returns true if the login was successful and false if it failed. This way the main form is not even created if login failed.


  12. 7 hours ago, Jud said:

    I also get this error when trying to start a new VCL project.

     

    Can someone help?

    The first thing I would try is to delete the DPROJ file (after making a backup, of course) and the open the DPR file for the project (with NO project group open) to force the IDE to recreate the DPROJ file. Unless you have exactly duplicated the folder structure on the new PC the project file may contain references to pathes that do not exist on your new PC.

    The error message seems to come from one of the layout components, perhaps a TGridPanel.  If you get it when creating a new VCL project with an empty form it has to come from the IDE itself, perhaps from a loaded 3rd-party package or expert.

    • Like 1

  13. 22 hours ago, bazzer747 said:

    As I understand it Firedac is not available in Professional. You need Enterprise for Firedac (or Architect)

     

    I've asked many times for Firedac to be available, even at extra cost, to add to Professional and it isn't happening. I moved to Enterprise some years ago on a really good deal (at that time FireDac WAS available in Professional) but find I don't really need all the functionality in Enterprise and because of the cost of keeping at the latest versions I can't afford an upgrade. I'd prefer to go back to Professional but with so many of my projects using Firedac it would be a mighty task to re-write all the data access elements in them. 

     

    So I'm never going to upgrade until something changes.

    FireDAC is available in the Pro edition, but the licence does not allow connection to server databases, only to local ones, as far as I remember. So you can use a local Interbase DB, for example but not write a program intended to allow multiple users to access an Oracle server, for example, if you access it via FireDAC. But there are other options, like using DbGo (OLE DB, for which you need to get the appropriate drivers for the target database from elsewhere, e.g. Microsoft) or 3rd-party solutions.


  14. 22 hours ago, programmerdelphi2k said:

    and Chars is not a "Ordinals"?

    Char (singular) is an ordinal type and can thus be used as index for an array but a string is not an ordinal type. The compiler will convert a single char to a string if required, e.g. if you assign a value/variable of type char to one of type string, but not vice versa. Even a string consisting of only a single character cannot be assigned directly to a variable of type char.

    • Like 3

  15. 15 hours ago, programmerdelphi2k said:

    is not a "ordinal" ...  array['0'.. '9']  of Char is valid!

    Char can be used as an index, but string cannot. Don't be confused by the fact that the syntax for declaring char and string literals is the same.


  16. 4 minutes ago, Willicious said:

     

     

    The above suggestions will run the code if i is equal to any number between 1 and 7. So, it's more like this:

    
    if (i = 1) or (i = 2) or (i = 3) or (i = 4) etc...

     

    What I need is for the code to run only when all numbers are satisfied, like this (note "and" instead of "or"😞

    
    if (i - 1) and (i = 2) and (i = 3) and (i = 4) etc...

     

    I realise that, of course, it's not possible for i to equal more than one value at once, that's why I need help with this. Essentially, it's a collision detection check in which the character has to turn around if they reach a vertical wall of at least 7 pixels in height, but  - all 7 pixels have to be filled. The following code works, but I want to try and simplify it if possible:

    
    if HasPixelAt(X, Y) and HasPixelAt(X, Y -1)
      and HasPixelAt(X, Y -2) and HasPixelAt(X, Y -3)
      and HasPixelAt(X, Y -4) and HasPixelAt(X, Y -5)
      and HasPixelAt(X, Y -6) and HasPixelAt(X, Y -7) then
    begin
    ...
    end;

     

    Thanks in advance, I hope this explains the question a little better.

    I see no other way to do this for vertical walls, since the memory locations of the pixels in question are not contiguous if the storage used has the typical bitmap layout.

     

    But you may be approaching the whole problem the wrong way. Instead of working directly with the bitmap image of the rendered scene you should build the scene as a list of objects, each of which represents an element of the scene. In this case the vertical wall would be one such object, storing its location and dimensions internally. You then walk over the list of objects and test whether the point (X,Y) falls inside such an object. This search can be sped up considerably by storing the objects in a tree or list sorted on coordinates. I have never worked in this area myself, but it is a common problem in game design, there should be plenty of literature around on the subject.

    • Like 1
×