Jump to content

PeterBelow

Members
  • Content Count

    562
  • Joined

  • Last visited

  • Days Won

    13

Posts posted by PeterBelow


  1. 12 hours ago, abdellahmehdi said:

    When I open a project, this problem appears.

     

     

    The  error message suggests that a component on one of the autocreated forms has not been created yet when some other component tries to refer to it when the IDE designer loads the form. This may be a sequence problem. Try to change the autocreation sequence to create the datamodule before the forms.

    • Thanks 1

  2. 48 minutes ago, neumimnemecky said:
    
    This is my new project, where I try to open bmp file and save it as jpg with NativeJPG by Simdesign.  https://sourceforge.net/projects/ahk...t.zip/download

    I did not uploaded images. Folder img should be created and in it bmp.jpg . Why nothing is created?

    
    procedure TForm1.LoadJpegFile(const AFileName: string);
    var bmp_filename, JpgFileName, dest_path: String; 
    begin BMP_filename := 'F:\bmp.bmp';
      JpgFileName := '.\img\bmp.jpg';
      dest_path := ExtractFilePath(JpgFileName);
      if not DirectoryExists(dest_path) then CreateDir(dest_path); 
      if not fileexists(bmp_filename) then 
        begin
        showmessage('File not found: '+bmp_filename);
        exit;
      end;
    try
      Bmp.LoadFromFile(bmp_filename); 
      Jpg.CompressionQuality := 100;
      Jpg.Assign(Bmp); 
      Jpg.SaveToFile(JpgFileName); // nothing happens?
    finally 
    end;
    end;

     

    Never rely on relative path names! They depend on whatever the application thinks the "current directory" is, and that is frequently not what you think it should be. Have you checked what destPath contains after your assignment?

    • Like 1

  3. 13 hours ago, ginnix said:

    AssignFile(F, 'c:\tmp\test.txt');
      Rewrite(F);
      for i := Low(CompanyDataBase) to High(CompanyDataBase) do
       Write(F, CompanyDataBase);
       CloseFile(F);

    Have you tried the obvious:

    AssignFile(F, 'c:\tmp\test.txt');
    Reset(F);
    for i := Low(CompanyDataBase) to High(CompanyDataBase) do
       Read(F, CompanyDataBase[I]);
    CloseFile(F); 

     


  4. 4 hours ago, neumimnemecky said:

    On D7 I try to install the package from here:

    https://github.com/acbarbosa1964/simdesign/tree/master/simlib/nativejpg

    There are some dependencies on simdesign-master\simlib\general

    so I have tried to create my own package with general and compile/build it. Also the

    simdesign-master\simlib\nativejpg\packages\NativeJpgD7.dpk I have tried with the same error.

    in general/sdStringtable.pas on line 75 there is this component needed:

      TsdStringTable = class(TsdDebugComponent)

    which is contained in simdesign-master\simlib\debug\sdDebug.pas

    But still the error is like it is not declared. Any advices how to compile this for Delphi 7?

    Have you added simdesign-master\simlib\debug to the project search path?


  5. 7 hours ago, AlanScottAgain said:

    Hi

    I have an object that holds a TObjectList.

     

    I have a helper class that builds The objects that go into the TObjectList.

    Currently I just Assign the helper ObjectList to the RootObjectList.

     

     RootObject.ObjectsList := Helper.DrawingObjectsList;

     

    I was wondering if I should Free the RootObjectList - if it has objects - before I assign the new list?

     

    Otherwise what happens to the old possibly orphaned list? Does the compilers take care of it?
    I have OwnsObjects set to True.

     

    Thanks

    Alan

    Object references are not automatically managed by the compiler-generated code, unlike interface references. So your code has a couple of possible problems re lifetime control:

    • If the assignment just replaces the RootObject.Objectlist (the internal reference held by RootObject) you leak the old object list's memory, as well as the objects held by the old list. After the assignment you now have two object list references referring to the same objectlist instance, one in RootObject.Objectlist, the other in Helper.DrawingObjectlist. If you free one the other becomes invalid and will cause an AV when next accessed.
    • If the assignment resolves to a call to a setter method (i.e. RootObject.Objectlist is a property with a setter method) and the setter frees the old reference before storing the one passed in you do not leak memory for the old list, but you still have two references to the same object list, with the problems mentioned above.
    • If the assignment resolves (via setter method) to clearing the content of the internal list first (assuming OwnsObject = true, so the contained objects are freed) and then storing the content of the passed list into the internal list you don't have the two problems mentioned in the first bullet point, but you have another: you now have two lists holding references to the same objects. Free an object in one list and the reference in the other becomes invalid. Especially fun if both lists have OwnsObjects set to true.
    • If the assignment resolves (via setter method) to clearing the content of the internal list first (assuming OwnsObject = true, so the contained objects are freed) and then moving the content of the passed-in list to the internal one you don't have a memory management problem, but the source list is now empty after the assignment. That may not be acceptible, depending on your requirements.

    There are two ways out of this mess:

    1. Change the design from using object references to using interface references. This gives you automatic lifetime control of the objects behind the interfaces via reference counting.
    2. Implement a deep copy mechanism for the objects held in the lists. The assignment would then clear the old content of the list and then store copies (clones) of the objects in the source list into the internal list. This way the two lists are completely independent of each other, changing objects in one has no effect on the objects in the other. Both lists can have OwnsObject = true and there will be no memory leaks.

     


  6. 6 hours ago, Fuandi said:

    Hi, I need to do base64 decoding then decrypt the result with aes256

     

    I managed to do it in linux, this is the command

    printf "<encrypted string>" | base64 -d | gpg --no-options --batch --cipher-algo AES256 --passphrase "<client secret>" --decrypt

     

    How to do this with delphi ? Anyone can help me ?

    Well, Delphi has the System.NetEncoding.TBase64Encoding class you can use for the first step to convert the string to an array of bytes (TBytes) or put it into a stream directly, e.g. a TMemorystream. The decryption is a different matter, though.  There was a recent thread on using the free Lockbox 3 library for this purpose on these groups. See here...


  7. 4 hours ago, gioma said:

    in the original project use of graphic components.
    In that case I have problems with the visualization of these components (buttons, labels, etc.) ..
    All this always if the form has the visible = false property.
    It is probably a component problem, but the fact that with standard components I get such an error makes me think there is so much more.

    Just to explain your problem: the VCL creates window handles on an as needed basis, which may delay this action until the window is shown and needs to be drawn.  In your example (without Synchronize) this causes the window handle to be created in the background thread, not the main thread, and that thread has no message loop...


  8. 38 minutes ago, A.M. Hoornweg said:

    Hello all,

     

    I have the impression that Delphi's SHL operator only handles 32 bits even when compiling for 64-bit.   

     

    Does anybody have an alternative routine that handles 64 bits?

     

    
    function bit(idx,value: uint64): Boolean;
    begin
      Result := ((1 shl idx) and value) <> 0;
    end;
    
    procedure test;
    var i:uint64;    b:boolean;
    begin
        i:=$ffffffff00000000;
        b:=bit(33,i);  // Should return TRUE but returns FALSE
    end;

     

    Your test case is in error, your value i has all top 32 bits set to zero.

  9. panel


    3 hours ago, abdellahmehdi said:

    How to make semi-transparent panel in Delphi VCL

    Set the ParentBackground property of the panel to true.

    • Thanks 1

  10. After opening the project go to the Project Manager pane; it's docked to the right of the editor by default. Under the project node you should have a noded named "Target platforms". Right-click on it to get a menu with an "Add platform" caption. Click that to get a list of available platforms, select "Windows 64 bit" from that. You should now have two subnodes under "Target platforms", double-click on the one you want to build to activate it.


  11. 2 hours ago, Henry Olive said:

    Good Day,
    MyCode in Database = VARCHAR(20)

     

    MyCode could be 

    (120 or 250)  like 3 digit Integer,  or

    (200.001  or  600.010)  there is a dot between numbers,  or

    (500.005.0010 or 100.010.1500)   there are 2 dots between numbers

     

    I need to Increase MyCode by 1  that is

    if MyCode = 100 then requested result = 101

    if MyCode = 300.001 then requested result = 300.002

    if MyCode = 600.005.0010 then requested result = 600.005.0011

     

    How can i do that

     

    Do it on the string itself, like you learned addition in school. :classic_cool:

    function incrementID(const aID: string):string;
    var
      ch: Char;
      N: Integer;
    begin
      Result := aID;
      N:= Length(Result);
      while N > 0 do begin
        ch := Result[N];
        case ch of
          '0'..'8': begin
                      Result[N] := Succ(ch);
                      Break;
                    end;
          '9': begin
                 Result[N] := '0';
                 Dec(N);
               end;
          '.': Dec(N);
        else
          raise Exception.CreateFmt('Invalid character "%s" in ID "%s" at position %d.',
            [ch, aID, N]);
        end; {case ch}
      end;  {while}
    end;

     

    • Like 2

  12. 2 hours ago, Der schöne Günther said:

    That they cannot be passed as var or out was more a comparison to simple fields, I should have made that clearer. Meaning: If you don't need getter/setters, I fail to see why you would ever go with properties at all.

    You can change the visibility of properties inherited from an ancestor, you cannot do that with fields. The VCL itself makes heavy use of that.


  13. 3 hours ago, direktor05 said:

    Ah you used LockBox component... what a shame! Real professionals don't use other people's components they make their own. But it's OK, it works.

    Real professionals have to earn money with their works, they don't have the time to reinvent the wheel, debug and validate it. If you want to shoot yourself in the foot be my guest, but don't expect me to supply the bullets...

    • Thanks 1
    • Haha 3

  14. On 6/17/2022 at 7:27 PM, direktor05 said:

    Ok thanks I think the problem with the above code is that it gives whole file buffer as input while only 16 B is acceptable. Thats why it takes first 16 B and the rest throws away. The right way should be ReadBlock 16 by 16 B until EOF and perform readblock 16B - encrypt 16B - write 16 B until EOF.

    Attached find a little example program that definitely works :classic_cool:.

     

    FileEncryption.zip


  15. 3 hours ago, direktor05 said:

    Yes, but its component. Is there any standalone unit? Like this one: https://github.com/stijnsanders/tools - has standalone units in crypto folder, but unfortunately they do not produce accurate results: https://github.com/stijnsanders/tools/tree/master/crypto 

    https://github.com/stijnsanders/tools/blob/master/crypto/aes.pas - when encrypting binary file I get only 16 B file back. But no error when building/compiling.

    You don't need to install the component, it is just a convenience wrapper. I'll try to create a small demo over the weekend, no time at the moment.


  16. 7 hours ago, zsleo said:

    I am using Delphi 11.1 Enterprise.


    I have an app that is now very commonly deployed and accessed though Windows RD Web.


    Often one of my forms “disappears” behind another for and the use thinks my application has hung because they cannot take control of the form that is displayed uppermost.


    There is a feature used by Microsoft to display the apps and sometime forms for each session as shown in the red box in Picture_1.png.


    The form types in my app are both modal and non-modal.

    Make sure that all modal forms have PopupMode set to pmAuto and in the dpr file you have

    Application.MainformOnTaskbar := true;

    That avoids such isssues at least on classic Windows systems. I know nothing about Windows RD Web, though.


  17. 1 hour ago, direktor05 said:

    Hello, does anybody know of any good Delphi AES (or similar) unit to encrypt/decrypt binary files? I found plenty however none works well - there is loss of information or can only encrypt/decrypt strings. Must be able to encrypt/decrypt binary file without loss of information - after decrypting back to original the exe file must be exactly the same in size.

     

    Help is needed.

    I use Lockbox 3 for such purposes.


  18. 2 hours ago, Thomas Lassen said:

    I am in the process of updating from 10.3.2 to 11.1, I have run into a major problem that I have not been able to solve: Upon updating to the 11.1 my GUI is complete destroyed, fx font sizes and widths of all my labels have changed. The same problem applies to all the control on my main form. Other forms that are a part of the project seem to be unaffected.

     

    Has anyone experienced a similar problem?

     

     

    See Tools -> Options -> User interface -> Form designer -> High DPI, the designer itself is now DPI aware and you may have to change the default setting if you design on a high DPI monitor.


  19. 13 hours ago, patrik-xyndata said:

    Hello, I'm using Delphi on macOS with Parallels, with setup 500% scaling.

     

    Text Editor looks like it should, everything is fine.

    But in designer the components and everything is sooooo small, that I can't read it / see it.

     

    When the App is compiled, everything looks just fine....

     

    I do not know what to do 😞

    In Delphi 11 the designer itself can be configured to be DPI-aware. Which version are you using?


  20. 1 hour ago, PeterPanettone said:

    I suspect a bug in the IDE itself. So I am not sure whether madExcept could help here. If the IDE were open-source, it would be easy to catch the bug.

    Unlikely, it would be reported much more frequently in this case. I have never seen it, for example, but in my case the only 3rd party package used is MMX...


  21. 3 hours ago, Rollo62 said:

    Thanks, Peter.

    Thats what I assumed too, but is there any deeper explanation how overload resolution of Char and String really works, and how this could be solved ?

    Maybe even the general resolution between Char and String.

     

    I understand that a String can be made of one Char 'a', which may be resolved as Char or String, which leads to ambiguities.

    Is there any clever trick to make this type references clear, and maybe even workable in overloads ?

    - I can use casts ( but that won't work for overlaod either )

    - I could define and cast to my own types, like MyChar and MyString ( which is also not very elegant )

    - Maybe constants like #13, #10, #0 have more "char-type-ness" than their string '' conterparts, but in practice that doesn't help much.

     

    Pascal has had the reputation of being the most type-safe language for quite some time, but just that char/string ambiguity has always left a bad taste, at least for me.

    I always wondered if these types cannot be made more "type-safe" nicely somehow.

     

     

     

    I think the core of the problem is an ambiguity inherent in the original language syntax inherited from the days of Turbo Pascal and earlier. 'x' can be interpreted either as a character constant or a string constant, and the compiler decides which it should be dependent on the context. A char is also assignment compatible with a variable or parameter of type string (but not vice versa).

    I see no way to get around this, and changing these rules will never happen since they make sense and changing them would break heaps of older code.

     

    Of course the compiler could use more stringent rules for overload resolution, e.g. require type identity and not only assignment compatibility. That would solve the conflict in the case you noticed but would be quite bothersome in other situations, requiring more overloaded versions of a function to be implemented. Think about what a type identity requirement would mean for overloaded functions taking numeric types as parameter. Do you really want to declare versions for byte, smallint, integer,  word, cardinal etc. ?

    • Like 2

  22. 4 hours ago, Rollo62 said:

    Hi there,

     

    I'm looking for an IndexOfAny( array or string, ... ) function, and find that there is already one in the TStringHelper.

    Unfortunately this is declared as a private function.

     

    
      TStringHelper = record helper for string
        ...
      private
        ...
        //<== NICE TO HAVE
        function IndexOfAny(const Values: array of string; var Index: Integer; StartIndex: Integer): Integer; overload;
        ..
      public
        ...
        // Maybe these bites with above declaration, as Char may interpreted as string too ?
        function IndexOfAny(const AnyOf: array of Char): Integer; overload;
        function IndexOfAny(const AnyOf: array of Char; StartIndex: Integer): Integer; overload;
        function IndexOfAny(const AnyOf: array of Char; StartIndex: Integer; Count: Integer): Integer; overload;
        ...
    end;

    I'm not realy sure why this function is hidden.

    Maybe because Char and String might cause issues when mixing in a overload, I haven't checked what would happen when making this public too ?

     

     

     

    There would probably be a conflict in overload resolution.

     

    Anyway, System.StrUtils contains IndexStr and IndexText functions that would serve your need here.

×