Jump to content

PeterBelow

Members
  • Content Count

    454
  • Joined

  • Last visited

  • Days Won

    12

Posts posted by PeterBelow


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


  2. 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;

     


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


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

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


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


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


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

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


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

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


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

  13. 5 hours ago, Willicious said:

    But, what if you only want to run the code when "i" matches every value between 0 and 7 at the same time?

    That makes no sense, a variable can only have one value at a time. Of course it may be a complex "value", like an array or set, but that does not seem to be what you want.


  14. 14 hours ago, Willicious said:

    I have a form with a treeview, which can be browsed using the arrow keys. Once an item in the treeview is selected, hitting an "OK" button on the form (which has the modal result mrOK) will close the form, and load the currently selected item into the app.

     

    What I want to do is assign VK_RETURN (which I believe is the [Enter] key...?) to the OK button, so that when browsing the treeview using keys, the user can just hit Enter/Return to load the currently selected item.

     

     

    Just set the buttons Default property to true, it will then automatically "click" when the user presses Enter/Return and the active control does not handle the key itself. No code needed...

    • Like 2

  15. 19 hours ago, softtouch said:

    Thanks for that. But the user edit the key in the valuelisteditor grid, Ido not add the key with insertrow or such. There are existing entries, the user select the entry to edit and change it, and when the user leaves the cell (with mouse or keyword/arrow keys for example), the exception is triggered.

    Try to handle the OnSetEditText or OnValidate events.


  16. 2 hours ago, Robert Gilland said:

    I am trying to create a function that creates a class at runtime lie this:

     

    function CreateDescentantClass( pcAncestorClass : TClass; const psDescendentClassName : String 😞 Class;

    begin

      Result := psDescendentClassName of  pcAncestorClass;

    end;

     

    Is this possible? I am using Delphi Alexandria

    Basically you have to enumerate all classes defined in the application and check their classname and ancestry to find one that matches the criteria you pass to the function. So it is misnamed: it does not creaste a class, it searches for one and returns it. The enumeration can be done using the advanced run-time type information support provided by the System.Rtti unit. You start with a variable of type TRttiContext, which has a GetTypes method to enumerate all types that have advanced RTTI info available. You check with the individual types IsInstance property whether it describes a class type, use the AsInstance property to obtain a TRttiInstanceType and use its methods and properties to examine the class to see whether it matches your criteria.

     

    There are two drawbacks to be aware of: RTTI generation can be disabled for individual units or even the whole application through compiler switches ($RTTI), so may not be available for 3rd-party classes you use, and RTTI can be used to examine the compiled executable and thus be considered a security risk.

     

    If you need this funktionality only for a limited set of classes it may be better to just create your own class registry and register all relevant classes in it in the initialization sections of the relevant units.


  17. 12 minutes ago, Philip Vivier said:

    When I click

    Tools->Options->Language->Delphi->Library -> [...] button, the whole system hangs. Does not matter on which [...] button I click.

    I need to stop Delphi every time with task manager.

     

    I am using windows 11 and Delphi 1.2.

    You can select and copy the path from the edit field and paste it into Notepad to check it for invalid characters or nonexistent pathes, perhaps that reveals a problem.


  18. 13 hours ago, msd said:

    Hello, 

     

    I would like to develop a KBMMW-based Windows Service Application.

    So I need a little assistance with this idea, with code for starting and monitoring KBMMW components.

    KBMMW is some kind of middleware framework that connects to databases and provides server connections to clients.

    So, I need to develop a classic Windows service application, which has a part where I need to register services and start the KBMMW Server listener to true.

    Do I need to execute the main thread of the service app because the KBMMW server is a listener on the port by itself, and is it ok to put this part of the code (registration services) in the service start event handler?

     

    Thanks in advance...

    You can only put code in the OnStart event handler that executes fast and does not block the thread, otherwise it will prevent the service from starting because the service manager runs into a timeout waiting for the event handler to return. Better just create a secondary thread in OnStart and do all other work in/from its Execute method.

    • Like 1

  19. 7 hours ago, Ian Branch said:

    Hi Team,

    One last aspect.

    I don't need to att, but if the Customer asks, where/how would I incorporate a printersetup dialog so they could select the printer and parameters?

     

    Regards & TIA,

    Ian

    Launch the dialog before you do anything with the Printer object (i.e. construct your print job). The VCL TPrintDialog and TPrinterSetupDialog components modify the Printer properties according to the user's selection in these dialogs.

×