Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 11/19/20 in Posts

  1. David Heffernan

    Hex2Binary

    I'd probably write it something like this: function HexToBin(const HexValue: string): string; const BinaryValues: array [0..15] of string = ( '0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111' ); var HexDigit: Char; HexDigitValue: Integer; Ptr: PChar; begin SetLength(Result, Length(HexValue) * 4); Ptr := Pointer(Result); for HexDigit in HexValue do begin case HexDigit of '0'..'9': HexDigitValue := Ord(HexDigit) - Ord('0'); 'a'..'f': HexDigitValue := 10 + Ord(HexDigit) - Ord('a'); 'A'..'F': HexDigitValue := 10 + Ord(HexDigit) - Ord('A'); else raise EConvertError.CreateFmt('Invalid hex digit ''%s'' found in ''%s''', [HexDigit, HexValue]); end; Move(Pointer(BinaryValues[HexDigitValue])^, Ptr^, 4 * SizeOf(Char)); Inc(Ptr, 4); end; end; Some notes: A case statement makes this quite readable in my view. You really don't want to be wasting time using Pos to search within a string. You can get the value directly with arithmetic. I prefer to perform just a single allocation, rather than use repeated allocations with concatenation. You might want to consider how to treat leading zeros. For instance how should you treat 0F, should that be 00001111 or 1111? I'd expect that both would be desirable in different situations, so an option in an extra argument to the function would be needed.
  2. Mahdi Safsafi

    Hex2Binary

    @David Heffernan Few remarks about your code if you don't mind : 1- Its pointless to use string when characters are fixed in size ... Simply use static array of X char. 2- Its also pointless to calculate index when you already used a case ... Simply declare your array using char-range. In your case, compiler generated additional instructions to compute the index. function HexToBin2(const HexValue: string): string; type TChar4 = array [0 .. 3] of Char; PChar4 = ^TChar4; const Table1: array ['0' .. '9'] of TChar4 = ('0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001'); Table2: array ['a' .. 'f'] of TChar4 = ('1010', '1011', '1100', '1101', '1110', '1111'); var HexDigit: Char; P: PChar4; begin SetLength(Result, Length(HexValue) * 4); P := PChar4(Result); for HexDigit in HexValue do begin case HexDigit of '0' .. '9': P^ := Table1[HexDigit]; 'a' .. 'f': P^ := Table2[HexDigit]; 'A' .. 'F': P^ := Table2[Chr(Ord(HexDigit) xor $20)]; else raise EConvertError.CreateFmt('Invalid hex digit ''%s'' found in ''%s''', [HexDigit, HexValue]); end; Inc(P); end; end;
  3. bazzer747

    FireDAC Add On discountinued? (Good by Embarcadero?)

    I used Delphi Professional for years, and had the Firedac add-on as together they gave me all I wanted from the product. I'm not into cross-platform development or server development so Enterprise was of no interest. Until they stopped the FireDac add-on in Profession a few years back. However, at the same time, they did a very good deal (so I thought!) to migrate to Enterprise, which includes Firedac. Which I did. Pity, I should have bitten the bullet then and used a different method of connecting databases, and stuck with Professional. All my projects used Firedac quite intensively so to move away from Enterprise now would be a major step. The cost of an Enterprise licence went up over 30% this year, completely unjustifiable in my opinion, and I've therefore lapsed my licence. 10.4.1 is where I am and where I'll stay for the foreseeable future.
  4. Even though we are a Delphi forum, we have a considerable number of users of the C++Builder among us. Without shifting the basic focus of this forum, we are aware of the long and close connection between Delphi and C++Builder and therefore want to give its users space for their questions. https://en.delphipraxis.net/forum/41-general-help/
  5. Marco Cantu

    November 2020 Roadmap

    Available at https://blogs.embarcadero.com/rad-studio-roadmap-november-2020/ Also, PM commentary at https://blogs.embarcadero.com/rad-studio-november-2020-roadmap-pm-commentary/
  6. Stano

    FireDAC Add On discountinued? (Good by Embarcadero?)

    They mainly push us there, which a large part of users do not want. Personally, I only need the Windows platform (VCL). Unfortunately, I'm not alone ...
  7. David Heffernan

    Hex2Binary

    Ugh. You can't rely on getting an AV. Don't ever write code like this.
  8. Renate Schaaf

    Project Bitmaps2Video on GitHub

    This is my video-project on GitHub: https://github.com/rmesch/Bitmaps2Video I am presenting it here, because it is useful as it is, but could use some ideas for improvement. Features: A Delphi-class to support encoding of a series of bitmaps and video clips to a video file Requires the ffmpeg-library and is intended as an easy to use interface to this library Versions for Win32/Win64 and a cross-platform version currently supporting Win32/Win64/Android32/Android64 Most popular file formats and codecs supported, more codecs contained in FFMpeg can be registered Rudimentary support for adding an audio-stream Demos for both versions, set up to compile and run "out of the box", as library files and support for their deployment to Android are included There are some problem areas though, the most important one in my opinion being threading issues with TBitmap under Android. For more see the readme and the demos. Critique, ideas, bug reports most welcome, maybe someone would even like to contribute, that would be delightful. There have been valuable contributions so far, but there are some areas which could use the input of an expert. Thanks for reading, Renate
  9. Uwe Raabe

    64 bit compiler running out of memory

    Perhaps this may help a bit: UsesCleanerSource.zip
  10. Darian Miller

    Is datasnap Webbroker a good approach?

    There are quite a few different avenues you could take to support API development. The first step in any is to get it "to work" which you seemed to have accomplished! Your next question is valid - will it scale? The question remains, how much do you need it to scale? How many concurrent connections are planned, what sort of total throughput is required and what are acceptable latencies? Once you define those, you can test those things yourself by using tools like JMeter and BlazeMeter and see if your performance is acceptable. If it's not, then you can look at scaling methods, either locally with Windows Clusters or migrating to cloud services on AWS or Azure. If the performance isn't satisfactory, you could also look into different implementations. One of the most commonly used frameworks is mORMot which has been highly optimized. If you join their community you'll likely get some help getting started. There's a LOT of code available, and much you can ignore to get started. Another option is to get a commercial finely-tuned multi-tier approach from Components4Developers. This option has been around a very long time and is quite mature, and quite performant. Another commercial option to look into is the Remoting SDK from remobjects. This also has been around quite a long time and is widely used. For a real simple and performant commercial toolkit, also look at RealThinClient components. There are plenty of other choices out there. The next step that I would recommend is to analyze your projected usage and start establishing some real testing metrics that you can validate current and future decisions on. Get the tools in place to back up your API infrastructure with measurements and validation. In addition to API testing, get line-by-line performance measurements with ProDelphi or Nexus Quality Suite to track down different implementations.
  11. Lajos Juhász

    64 bit compiler running out of memory

    The easiest way to kill the compiler is to have huge cyclic unit dependencies. Try to reduce that. Also if the project was created before unit scope names were introduced you should add the scope names to the units in the uses lists and remove from project options in Unit Scope Names.
  12. David Heffernan

    Hex2Binary

    No guarantee that an out of bounds array access leads to an exception. You have just been unlucky that you've seen one every time you ran your code. Once again, nobody should ever write code like that.
  13. Juan C.Cilleruelo

    FireDAC Add On discountinued? (Good by Embarcadero?)

    Change from FireDAC to another set of components like Devart is not going to be a problem in my case. My software follows a strict MVC architecture. All the Models are independent of the rest for the application and in fact, there are tested as a separate unity. I have a project of Unit-Tests that test separately all the models without link any Controller. Only some functionalities of FireDAC I'm going to miss, but I'm sure that in a new set of components I'm going to find new functionalities too, that is going to make more special the experience. The problem, in my case, is the frustration of making plans and see how Embarcadero doesn't take you into account. To see that Embarcadero trace his own plans without the worry about the plans of his customers. What's Next? Eliminate Professional version, perhaps? They coming bad times to all of us. Times in which the price can be a very, very, very important thing in all the ambits. In these new times, decisions based exclusively on money are going to be frequent.
  14. Hi All For those who are interested, I have made some progress on this project, and have uploaded an installer with the command line tool and IDE plugins for XE2-10.4 - it's still very much an alpha version (not feature complete or stable) but at least shows the direction I'm heading in. I have added some quick notes on how to get started with dpm https://github.com/DelphiPackageManager/DPM/blob/master/GettingStarted.md The installer can be found here https://github.com/DelphiPackageManager/DPM The IDE plugin is still a bit rough around the edges but reasonably stable. Note that installing design time packages is still being worked on. Most of my open source projects have package binaries under the releases tab (the getting started notes show what to do with them). It's still some way from being ready for production use, we are still working on a website/package repository. If you are a library author, please do take a look. Creating packages is not at all difficult.
  15. Alexander Elagin

    Hex2Binary

    Copies four characters from the BinaryValues constant array item at index HexDigitValue to the location pointed by Ptr.
  16. Juan C.Cilleruelo

    FireDAC Add On discountinued? (Good by Embarcadero?)

    FireDAC "A D D - O N " is discontinued.
  17. FPiette

    TwSocket Udp Client how to receive Bytes Properly ?

    Response of Lajos is correct. But anyway, it is better to use a fixed size array as buffer to avoid allocation freeing a dynamic array as each data packet is coming. So write something like this instead: procedure TMainForm.WSocketDataAvailable(Sender: TObject; Error: Word); const BUF_SIZE = 1000; // Or whatever size fits your needs var ABytes : array [0..BUF_SIZE] of bytes; Len : Integer; begin Len := WSocket.Receive(@ABytes[0], BUF_SIZE); if Len = 0 then Exit; if Len < 0 then begin ShowMessage('Error receiving data'); Exit; end; // Process data... end;
  18. Lajos Juhász

    TwSocket Udp Client how to receive Bytes Properly ?

    First you've to initialize aBytes. Try something like this: setLength(aBytes, 1024); wsocket.Receive(aBytes, length(aBytes));
  19. Mike Torrettinni

    Hex2Binary

    This is what I use: // aHex is expected hex string of chars: 0..9, A..F function Hex2Bin(const aHex: string): string; const // Array of [hex, binary] pairs cBinArray: Array[0..15, 0..1] of string = (('0', '0000'), ('1', '0001'), ('2', '0010'), ('3', '0011'), ('4', '0100'), ('5', '0101'), ('6', '0110'), ('7', '0111'), ('8', '1000'), ('9', '1001'), ('A', '1010'), ('B', '1011'), ('C', '1100'), ('D', '1101'), ('E', '1110'), ('F', '1111')); var i: integer; x: string; begin Result:=''; // Iterate hex string for x in aHex do // For each hex char find binary result in cBinArray for i := Low(cBinArray) to High(cBinArray) do if cBinArray[i, 0] = x then begin // Concatenate binary results Result := Result + cBinArray[i, 1]; Break; end; end; Note: it expects valid Hex string input (0..9 and A..F chars), so if you need to validate if input is valid hex string, or make it UpperCase (a..f -> A..F), make necessary checks.
  20. Darian Miller

    FireDAC Add On discountinued? (Good by Embarcadero?)

    That's a honest question, when you know the answer?
  21. Alexander Elagin

    FireDAC Add On discountinued? (Good by Embarcadero?)

    Use UniDAC, which is not too expensive and is a good independent alternative to FireDAC. It also supports Lazarus and older versions of Delphi. Switching from FireDAC is not difficult. https://www.devart.com/unidac/
  22. Markus Kinzler

    FireDAC Add On discountinued? (Good by Embarcadero?)

    The database access components from DevArt are a good alternative to FireDAC.
  23. dummzeuch

    WinUI in Delphi (planned for 10.5?)

    Hm, when will Microsoft start to rewrite Office to use WinUI? Until that happens, I am skeptical whether this will be worth the effort. But I am only a disgruntled old white man^d^d^d^d^d^d^d^d^dVCL developer.
×