Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 03/20/21 in all areas

  1. Hi there, I want to show you my approach how to organize and ease modular designs. Usually I like to have one main access unit, and all much granularized sub-features distributed in separate units. The main and sub-units build a kind of tree of functionality, where each unit can stand alone, but usually all units are highly related between each other. To access and open those deeper layer units is usually much of a click-drill-down the unit tree, or a lot of search and select via search function or other tools. Here is the general layout I like to use, which has a lot of advantages for me: unit My.Thing; interface uses My.Thing.Intf , My.Thing.Factory // // , My.Thing.Impl // QuickAccessUses // , My.Thing.Events.Intf // , My.Thing.Events.Carrier.Intf // , My.Thing.Events.Carrier // , My.Thing.Common // , My.Thing.Features // , My.Thing.Features.Factory // , My.Thing.Features.Impl // , My.Thing.Feature.Intf ; You can place the cursor on the unit names, even if its inside of a comment, and with right click "Open file at cursor" you can directly open the desired unit. The advantages I see from my point of view: - a single point of access, for a larger structural, modularized tree - immediately all of the close-related units are visible on the screen - directly see the kind of structure, maybe leads to further unit refactorings - it is a most easy and fast way to find and navigate to the desired unit, and to open it - no tipping of unit names into searchboxes The disadvantages: - None ( except putting some extra lines in comments ) I like this a lot, and this works only due to the fact that "Open file at cursor" works also within comments. Thats why I want to ensure that the Embarcadero team is aware of this, and never is going to change the open behaviour in the future editors
  2. It appears you have already asked a similar question, here: https://stackoverflow.com/questions/65345853/is-it-possible-to-write-the-following-java-program-in-delphi The principal for your present issue is identical, i.e. if OnPrintListener is a class, then you. cannot do it in Delphi. If it's an interface (which, given your other question, it's likely), then you already have an example of how to implement a Java interface, in the StackOverflow answer. A possible example for this case: uses Androidapi.JNIBridge, Androidapi.JNI.JavaTypes, Androidapi.Helpers; type JOnPrintListener = interface; JOnPrintListenerClass = interface(IJavaClass) ['{076904DD-77D9-497D-BA21-992A9B8FED3E}'] end; [JavaSignature('com.nexgo.oaf.apiv3.device.printer.OnPrintListener')] JOnPrintListener = interface(IJavaInstance) ['{F688775D-067F-4521-A045-9106599F4C4A}'] procedure onPrintResult(retCode: Integer); cdecl; // *** NOTE *** There may be other methods for this interface end; TJOnPrintListener = class(TJavaGenericImport<JOnPrintListenerClass, JOnPrintListener>) end; TRunnable = class(TJavaLocal, JRunnable) private FCallback: TProc; public { JRunnable } procedure run; cdecl; public constructor Create(const ACallback: TProc); end; TPrintListener = class(TJavaLocal, JOnPrintListener) private FRetCode: Integer; FRunnable: JRunnable; procedure DoRun; public { JOnPrintListener } procedure onPrintResult(retCode: Integer); cdecl; public constructor Create; end; { TRunnable } constructor TRunnable.Create(const ACallback: TProc); begin inherited Create; FCallback := ACallback; end; procedure TRunnable.run; begin FCallback; end; { TPrintListener } constructor TPrintListener.Create; begin inherited; FRunnable := TRunnable.Create(DoRun); end; procedure TPrintListener.DoRun; begin // Do the toast thing here, using FRetCode end; procedure TPrintListener.onPrintResult(retCode: Integer); begin FRetCode := retCode; TAndroidHelper.Activity.runOnUiThread(FRunnable); end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin // Assuming FPrintListener is defined as: FPrintListener: JOnPrintListener FPrintListener := TPrintListener.Create; // Assuming you have created an instance of Printer (imported as JPrinter) called FPrinter FPrinter.startPrint(False, FPrintListener); end; Note all of the assumptions being made - the biggest one being that OnPrintListener is an interface. Also I don't have the .jar, nor the printer, so of course it is untested
  3. Uwe Raabe

    Scalable IDE Toolbar icons?

    Of course it would. It is just that all others are completely incompetent. 🤦‍♂️
  4. A few notes: - the position array will very likely be rather short - unless you going to replace words in a novel or something like that. Handwritten InsertionSort will outperform that. - avoid dynamic allocation for the position array - use a static array with a reasonable standard size and only fall back to dynamically allocating if that is not enough - after fixing that I get an improvement of around 1/3 over the code you posted and now SamplingProfiler tells me that the code stays in System.Pos for like 50% of the time - that cannot be right Also you have a bug: AddTestCase(vTestCases, 'ReplaceReplaceString', ['Replace', 'FooString'], ['Foo', 'Bar']);
  5. Initial idea that multiple scans are bad for performance is good, but your steps are wrong. You should scan the string for all substrings in one go, but you should also build new string while you are scanning. Using TStringBuilder or similar pattern with preallocated buffer would be appropriate. And when I sad scanning string for substrings, don't use Pos function. Scan string one character at the time and match it with patterns you are looking.
  6. Lajos Juhász

    Scalable IDE Toolbar icons?

    Delphi 10.5 should introduce DPI friendly IDE, we have to wait only about 4-6 months to see it.
  7. Uwe Raabe

    Delete a Registry Key...

    Any subkeys of the key need to be deleted first. TRegistry.DeleteKey already takes care of that, but it needs KEY_ENUMERATE_SUB_KEYS access for that, which is not included in KEY_WRITE. Try KEY_ALL_ACCESS.
  8. Remy Lebeau

    Thread Issues: using resume and start

    If the sole purpose of the thread is just to delay a UI notification, then TThread.ForceQueue() would be better, no thread needed at all: procedure THeaderFooterForm.Button1Click(Sender: TObject); begin TThread.ForceQueue(nil, procedure begin HeaderLabel.Text := 'My Job'; end ); end;
  9. Fr0sT.Brutal

    Database in Delphi

    Zeos of course
  10. Remy Lebeau

    tlsv1 alert protocol version

    You need to upgrade to the latest Indy, yes. Indy 10 still supports Delphi/C++Builder 6.
Ă—