Jump to content


Popular Content

Showing content with the highest reputation on 09/29/20 in all areas

  1. pyscripter

    Using the New Edge browser control

    One of the new features of Delphi 10.4 was the new TEdgeBrowser component. It is nice. However the downside is that certain steps are needed for the use and delployment of this component: Install Edge WebView2 package via GetIt. This places a Dll called WebView2Loader.dll in the redist directory of Embarcadero studio (one for win32, one for win64). The appropriate WebView2Loader.dll needs to be deployed alongside your executable. (about 300Kb). While developing you can add a post-build event to do that. Now the difficult one was that you had to replace the stable version of Edge, installed and managed by Windows, with the unstable one from the Canary Edge update channel (daily updates). Event if you did that in your own machine, few users would accept it. The new thing, that is not mentioned in the documentation, is that there is a better alternative to the third requirement. You can use the WebView2 Runtime installer which works independently from and does not interfere with your browser, and can be safely deployed in customer sites. Give it a try.
  2. Anders Melander

    How to operate a private field in other unit?

    I dnt knw bout u, bt I gt $ 4 the Q of my cde. Not for the amount of keystrokes I can save.
  3. How to call a private method of a class inside a Berlin+ class via Helper procedure TSomeClassHelper.CheckAccessToPrivate; begin With Self do begin // access via with works FInt :=1; SomeMethod; end; end; // Declared in another unit as: type TSomeClass = class private FInt : integer; procedure SomeMethod; end;
  4. I imagine one of the biggest problems of being self-taught is missing out on some well-documented practices. Well, I confess that I did not know about the use of double-dabble to quickly manually convert a base-2 representation to base-10, for example: 1001000110 to 582. Quick blog post published today: https://www.ideasawakened.com/post/double-dabble-and-conversions-from-base-10-and-base-2-number-systems
  5. A.M. Hoornweg

    "Simulating" a com port with data arriving

    VMWare workstation will let you do this. Just add two virtual serial ports to the VM, in the field "connection" specify "named pipe". Both COM ports must use the same name for the named pipe (just call it "serialportpipe") and one port must be configured to be "server", the other must be "client". That way, the two COM ports are crosswired. Now you can start 2 applications, connect them up to the two COM ports and let them talk to each other.
  6. Stefan Glienke

    How to operate a private field in other unit?

    Hundreds of lines of code within one routine and you think that *with* is the problem? LOL
  7. Anders Melander

    Double-dabble to convert binary to decimal

    Ummm. I must be missing some deeper meaning here but what is the point of pretending that an integer values isn't already stored in binary format? I mean, I could understand if you were trying to implement bin/dec conversion on a denary computer but other than that this sounds like an algorithm for people that doesn't have access to computers.
  8. Shurely, we do and let me go on! A compiler flag (with: off) and good refactoring support is on my wish-list! I understand that since the debugger cannot figure out the scope then refactoring would maybe be tricky to implement 😞 IMHO "hate" is a very strong word that i seldom use, if at all. I hate with.
  9. I have mountain of things that need to be done right now, but what to say !, i am bored to hell and looking something to do away from what is needed, so. @Darian Miller this is special for you program BinaryNumbers; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; function IntToBin(Value: Integer; Digits: Integer = 0): string; var I, Len: Integer; Negative: Boolean; begin // Set boundaries and limits Negative := Value < 0; if Negative then Value := 0 - Value; Len := 1; while (1 shl Len) <= Value do Len := Len + 1; if Digits < 1 then Digits := 1 else if Digits > 31 then Digits := 31; if Len < Digits then Len := Digits; Len := Len + Ord(Negative); // Do translate SetLength(Result, Len); I := 0; while Value > 0 do begin Result[Len - I] := Char((Value and 1) + Ord('0')); Value := Value shr 1; Inc(I); end; // Fill leading zeroes, up to Digits, and add signal while I < Digits do begin Result[Len - I] := '0'; Inc(I); end; if Negative then Result[1] := '-'; end; function DoubleToBin(Value: Double; Digits: Integer = 0; FracDigits: Integer = 8): string; var I, Len: Integer; IntPart: Integer; FractalPart: Double; begin IntPart := Trunc(Value); Result := IntToBin(IntPart, Digits); // Prepare result for fractal part FractalPart := Value - IntPart; if FractalPart < 0 then FractalPart := 0 - FractalPart; if (FracDigits > 0) or (FractalPart > 0) then Result := Result + '.'; // Set boundaries and limits for fractal part Len := 0; if FracDigits < 0 then FracDigits := 0; if Len < FracDigits then Len := FracDigits; if Len = 0 then Exit; // Do translate I := Length(Result); SetLength(Result, I + Len); Inc(FracDigits, I); while (FractalPart > 0) and (I < FracDigits) do begin FractalPart := FractalPart * 2; Inc(I); Result[I] := Char(Ord(FractalPart >= 1) + Ord('0')); if FractalPart >= 1 then FractalPart := FractalPart - 1; end; // Fill trailing zeroes, up to FracDigits while (I < FracDigits) do begin Inc(I); Result[I] := '0'; end; end; function BinaryToInt(const Value: string): Integer; procedure NotValidOfIntegerException; begin raise Exception.Create('BinaryToInt Error : ''' + Value + ''' is not valid binary integer'); end; var I, S, Len: Integer; Negative: Boolean; begin // Check validity and set boundaries Result := 0; Len := Length(Value); if Len = 0 then Exit; Negative := Value[1] = '-'; if Negative then begin if Len = 1 then NotValidOfIntegerException; S := 2; end else S := 1; for I := S to Len do if (Value[I] <> '0') and (Value[I] <> '1') then NotValidOfIntegerException; // calculate for I := S to Len do Result := Result + (Ord(Value[I]) - Ord('0')) shl (Len - I); if Negative then Result := 0 - Result; end; // simple and naive conversion function, though the fractal part is OK with the standard // not IEEE X compatible as the integer part is considered as simple integer // in IEEE standards the integral part should be exponentially calculated and not converted into decimal function BinaryToDouble(const Value: string): Double; procedure NotValidBinaryOfDoubleException; begin raise Exception.Create('BinaryToDouble Error : ''' + Value + ''' is not valid binary double'); end; var I, P, Len: Integer; IntPart: string; Temp: Double; begin // Check validity and set boundaries Result := 0; Len := Length(Value); if Len = 0 then Exit; P := Pos('.', Value); if (P = 1) or (P = Len) then NotValidBinaryOfDoubleException; SetLength(IntPart, P - 1); for I := 1 to P - 1 do IntPart[I] := Value[I]; for I := P + 1 to Len do if (Value[I] <> '0') and (Value[I] <> '1') then NotValidBinaryOfDoubleException; // calculate fractal part if P > 0 then begin Inc(P); Temp := 1 / 2; for I := P to Len do begin Result := Result + Temp * (Ord(Value[I]) - Ord('0')); Temp := Temp / 2; end; end; // build final result if Value[1] = '-' then Result := 0 - Result; Result := Result + BinaryToInt(IntPart); end; begin Writeln(DoubleToBin(582.24, 16)); Writeln(DoubleToBin(582.24,0, 2)); Writeln(DoubleToBin(-582.24, 0, 32)); Writeln(DoubleToBin(-10/3,0,24)); Writeln(FloatToStr(BinaryToDouble('-11.010101010101010101010101'))); Writeln(FloatToStr(BinaryToDouble('0000001001000110.00111101'))); Writeln(FloatToStr(BinaryToDouble('1001000110.00'))); Writeln(FloatToStr(BinaryToDouble('-1001000110.00111101011100001010001111010111'))); Readln; end. the result 0000001001000110.00111101 1001000110.00 -1001000110.00111101011100001010001111010111 -11.010101010101010101010101 -3.33333331346512 582.23828125 582 -582.239999999991 Hope you find it useful and for your quest after converting the fractal part then it is way simple that what you think, start with 1/2 and half it with each step, waling the bit from the left to the right. ps : not fully tested but i think i mostly got it right at first try, if anyone find bug or have better and enhanced version of it or any other, please share here.
  10. dummzeuch

    Cast error when using Ctrl+#

    WTF? It's a bloody TMenuItem! That doesn't even have a common ancestor with TPopupMenu (apart from TComponent)! Who in their right mind would do that? Fixed in revision #3325
  11. Uwe Raabe

    "Simulating" a com port with data arriving

    I am pretty fine with Advanced Virtual Com Port
  12. dummzeuch

    "Simulating" a com port with data arriving

    Com0Com works for me (on Windows XP and 8.1 (haven't tested Windows 7 or 10), or simply a serial null modem cable that connects two serial ports, native or USB serial adapters.
  13. Hello all, when Delphi didn't know about unicode yet people would often stuff binary data into strings because strings were soooo practical and easy to manipulate. Yes that is and was bad practice and highly frowned upon, but as we all know it was done anyway and people got away with it because Delphi didn't care about code pages at the time so it just worked. It was even done in professional libraries. Code like that is very hard to port to newer Delphi versions which are unicode-enabled and codepage-aware and when you attempt a conversion, subtle errors may happen where you least expect it. If you still have precious old code libraries that do such things and which would be too costly or too complex to rewrite, you may consider trying this workaround as a quick & dirty fix: Type Binarystring= type Ansistring (437); The nice thing about code page 437 is that all 256 possible ansichar values map to valid unicode code points so you can safely assign these strings to Unicodestrings and back again without data loss and Delphi's built-in string functions won't break the binary data contained in these strings. So you just may me able to salvage some legacy code by declaring this new type and then replacing all "string" declarations in the code with "binarystring" and all (p)Char with (p)Ansichar. And yes, it's still bad practice... (The idea is originally from Raymond Chen: https://devblogs.microsoft.com/oldnewthing/20200831-00/?p=104142 )
  14. Thank you Dave, that was the solution to my problem....you save my life 😁👍
  15. David Heffernan

    Any Known Issues with ZCompressStream?

    They are. That's the a very plausible explanation. File corruption is something that does happen. You'll want to reproduce the issue before trying to solve the problem. And if it is file corruption then the solution is somebody else's problem.
  16. aehimself

    Any Known Issues with ZCompressStream?

    If you don't need anything fancy, you can use System.ZIP (or the updated System.ZIP2, which is a drop-in replacement offering some extras). I'm using Zip2 with smaller modifications, works like a charm.
  17. Remy Lebeau

    Workaround for binary data in strings ...

    True, though 437 does not map every byte (in fact, many bytes) to a Unicode codepoint of same numeric value. For this task (when I have needed to use it in the past), I would use codepage 28591 (ISO-8859-1) instead, which has bytes use the same numeric values as their codepoints. Agreed. More accurately, there is no conversion only when an AnsiString(N)-based string type is assigned to it, as it will simply inherit N as its current codepage, but it does perform a character conversion when a UnicodeString or WideString is assigned to it, and when it is assigned to another non-RawByteString string type. So, even if you were to use RawByteString, you still have to be careful with how you use it.
  18. OmarPerezH

    XCode 12 compile error

    Best way, 1- Export SDK from Delphi IDE Tools->Options->SDK Manager select SDK and export and import it in the new Delphi IDE
  19. Achim Kalwa

    remove ExplicitXxxx properties

    I know I am late to the party, but you might try the attached package for Delphi 10.4.1. It uses the hooking code from Andreas Hausladen's VclFixPack v1.4 to patch the TControl.DefineProperties method to a modified code, which does not write those Explicit* properties to the DFM file. Unpack the zip archive, open DControlsFix.dpk in Delphi 10.4.1, compile & install. There is nothing to customize. If this package is installed, the patch is active. If you like to get the default behaviour back, just uninstall the package. Use at your own risk 😉 DControlsFix.zip
  20. Jacek Laskowski

    livebindings without livebindings designer , code only

    I don't know the answer to the question, but it may be useful: https://github.com/malcolmgroves/FluentLiveBindings
  21. Sherlock

    XCode 12 compile error

    Sure, but then XCode 13 will be out....
  22. You have to use the Helper, only it and the use of WITH get you access, see my test code above. Plus that's not enough code for anyone to help you.. // Your helper should have a method like SetPrivateVar which uses 'With Self do' SomeClass.SetPrivateVar(TMyClassA2.Create());
  23. I have this test setup to let me know if this is ever changed in a new version of Delphi. Should be simple enough to replace TCustomTextFile with whatnot and run the test which I just ran in 10.4.1 and it passed: //MMWIN:CLASSCOPY unit _MM_Copy_Buffer_; interface implementation type TTestAccessToPrivateFieldHelper = class helper for TCustomTextFile function SetPrivateOwnsStream(AValue: boolean): boolean; end; { TTestAccessToPrivateFieldHelper } function TTestAccessToPrivateFieldHelper.SetPrivateOwnsStream(AValue: boolean): boolean; begin with Self do begin FOwnsStream := AValue; Result := FOwnsStream; end; end; end. //MMWIN:MEMBERSCOPY unit _MM_Copy_Buffer_; interface type THelperTests = class(TObject) public [Test(True)] procedure TestAccessToPrivateField; end; implementation procedure THelperTests.TestAccessToPrivateField; var F : TTextFile; begin F := TTextFile.Create('testing.txt', TEncoding.UTF8); try Assert.IsFalse(F.SetPrivateOwnsStream(False)); Assert.IsTrue(F.SetPrivateOwnsStream(True)); finally F.Free; end; end; end.
  24. You cannot access private fields of a class declared in a different unit. [Period] That is, if you play by the rules. There are various ways to still achieve that, but each of them relies on either some compiler quirk (e.g. class helpers could access private fields in some Delphi versions, but that loophole has been closed) or directly use the knowledge about the memory layout of the original class. The latter is done either with pointer arithmetic or by declaring a new class with the same fields and hard typecasting an instance to that class, which then allows accessing the private fields. Of course that would mean this class or pointer arithmetic must be adapted to every change that Embarcadero makes to the original, so the memory layout matches.
  25. Anders Melander

    How to operate a private field in other unit?

    I'm still hoping that with will be completely eliminated from the language. Here's a few lines from the code I'm currently working on: begin ...3-400 lines of code... with vPlan.DataController, dbSlaktePlan, BLPlan, Grupper ,Data[Id] do begin ...a few hundre lines more... with vPlan, BLPlan.SiteSum, Plans[Id] do begin ...and it goes on...