How to use units in delphi project group
I have a group of projects with 3 projects (standAlone, ISAPI, module for apache), until now they all have the same file.pas and when modifying code and compiling the .exe, the .dll and .so are updated.
I want to add another unit (.pas file) to better organize classes and make it easier to navigate through the project code.
My question is, should I add the new file.pas to the three projects or only to the standAlone? (use RAD Studio 10.2)
See also questions close to this topic
Delphi compare 2 stringlists by substring search and merge the matching items in another stringlist
I'm trying to compare 2 stringlist by substring search, and match the found items into another stringlist.
"Stringlist_SCSILogicalUnit" contains data like:
SCSIBus=0;SCSILogicalUnit=0;SCSIPort=1;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=1;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=2;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=3;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=4;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=43;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=44;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=45;SCSIPort=2;SCSITargetId=0;Status=OK SCSIBus=0;SCSILogicalUnit=46;SCSIPort=2;SCSITargetId=0;Status=OK
"Stringlist_LUN" contains data like:
LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 67 ; LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 43 ; LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 44 ; LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 45 ; LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 50 ; LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 51 ;
I need to match the corespondence between "LUN" value and "SCSILogicalUnit" value (LUN and SCSILogicalUnit have the same value Lun=SCSILogicalUnit)so that the result can be listen in "Stringlist_result". The result shoud look like
"SCSIBus=0;SCSILogicalUnit=46;SCSIPort=2;SCSITargetId=0;Status=OK =>>> LocationInformation REG_SZ Port(2,2,3,3) Bus 0, Target ID 0, LUN 46 ;"
I'm using the following function but the result is not consistent:
function stringlist_mmg_FastJoin(List1, List2: TStringList): TStringList; var L1Idx, L2Idx, L1Max, L2Max: Integer; v: Integer; begin // Create Result list, set it's min size Result := TStringList.Create; Result.Capacity := Max(List1.Count, List2.Count); // limits L1Idx := 0; L2Idx := 0; L1Max := List1.Count; L2Max := List2.Count; // forse sort List1.Sorted := True; List2.Sorted := True; // iterate while (L1Idx<L1Max) and (L2Idx<L2Max) do begin if pos(extracttextbetween(List1[L1idx],'SCSILogicalUnit=',';'),List2[L2idx])>1 then begin Result.Add(List1[L1Idx]+' = '+List2[L2idx]); Inc(L1Idx); Inc(L2Idx); end else if v < 0 then // Add from List 1 begin //Result.Add(List1[L1Idx]); Inc(L1Idx); end else // v > 0 // Add from List 2 begin //Result.Add(List2[L2Idx]); Inc(L2Idx); end; end; // Add all remainders from second list while L2Idx < L2Max do begin //Result.Add(List2[L2Idx]); Inc(L2Idx); end; end; stringlist_resultat:=Tstringlist.create; stringlist_rezultat.addstrings(stringlist_mmg_FastJoin(Stringlist_SCSILogicalUnit,stringlist_LUN));
When I run the function I get a sigle result.
Could someone please tell what am I doing wrong? Can this task be obtimized without a stringlist?
Delphi Indy TIdHTTP.Get() high CPU load
I saw a similar question here, but no useful answer, so let me please write it again.
My application is using too much CPU, for a test example I pick a slow site (https://www.hao123.com/) from top10 slowest sites, and read it with 100 threads simultaneously.
There is no response processing; one request is taking about 5 seconds, so it looks logical for me that my threads should use about 0% CPU being almost all the time waiting for a response.
procedure mth.Execute; var tm1: dword; begin HTTP:=TIdHTTP.Create; HTTP.ConnectTimeout:=60000; HTTP.ReadTimeout:=60000; ssl:=TIdSSLIOHandlerSocketOpenSSL.Create; HTTP.IOHandler:=ssl; HTTP.HandleRedirects:=true; HTTP.ProtocolVersion:=pv1_1; repeat sleep(5); If StartWork then begin tm1:=TimeGetTime; s:=HTTP.Get('https://www.hao123.com/'); GlobalTiming:=(GlobalTiming * 9 + (TimeGetTime-tm1)) / 10; end; until Terminated; HTTP.Compressor.Free; HTTP.Free; ssl.Free; end;
The test application starts creating threads with
StartWork=false. As long as I dont set
StartWork:=true, CPU load is about 0%
UPDATE: to answer comments below: 100 threads running
sleep(5)cycle DO NOT load CPU
As soon as I start readers by setting
StartWork:=true, I see 10% CPU load on my 16-core Ryzen. When running on a 1-core VDS, this turns into a really painful problem.
The question is: how is a simple operation which should just wait, actually using that much CPU? How to "optimize" it?
Hard to explain that the issue has nothing to do with the
sleep(5)so 2 more pictures:
sleep(100 + random(100))
The picture from 2-cores vds:
DCC Error E2597 ld: library not found for -lbz2
I am trying to compile one blank Delphi project targeting iOS Device 32/64 but getting this error
[DCC Error] E2597 ld: library not found for -lbz2 [DCC Fatal Error] F2588 Linker error code: 1 ($00000001)
My environment is Delphi Tokyo 10.2.3, MacOSX 10.13.5, XCode 9.4.1, iOS 11.4, iPhone 6s. On my project it's totally blank without any code just default Form. I also installed iOS 11.3 patch. Any help will be highly appreciated.
Building Delphi project from Visual Studio Code
I have already set up build and debug environment for Object Pascal inside Visual Studio Code via FPC and GDB, but I just made build process work for programs containing only 1 .pas file via
"command": "fpc", "args": [ "-g", "-Px86_64", "helloWorld.pas" ],
Now, I need to build quite big Delphi project group (something like solution?) and it contains main project file .groupproj.
Is there a way to build the .groupproj via FPC somehow?
Or at least some workaround like conversion to .lpi and then build via FPC?
Or at least call Delphi compiler/builder from VS Code and build the whole project group via it? (but I don't like this option, because I prefer to not use Delphi)
Is it possible to download files created on Stypi and in the same format?
I'm looking for a tool for programming in real time with my partners and Stypi seems very nice but the download option would be amazing.