mytbo
Members-
Content Count
21 -
Joined
-
Last visited
Community Reputation
5 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
With this data structure for the VST, it would be easier to use a class as a record for the tree data. The VST should better not hold the data, but only display it. This article shows how easy it is to map a data structure in VST. Here is the translation into English with Google Translator. The result is not perfect (rather not so good), also some formatting is destroyed, but it is readable. With best regards Thomas
-
Download HTML from server, save it as a file and execute the following: procedure TfrmMain.FormShow(Sender: TObject); begin EdgeBrowser.CreateWebView; end; procedure TfrmMain.EdgeBrowserCreateWebViewCompleted(Sender: TCustomEdgeBrowser; AResult: HRESULT); begin btnLoadHtml.Enabled := (AResult = 0); end; procedure TfrmMain.btnLoadHtmlClick(Sender: TObject); begin // ... download HTML from server, save it as a file EdgeBrowser.Navigate('file:///C:/Ambar/Temp/loginRetorno.html'); end; With best regards Thomas
-
Current alternatives for SMTP with TLS 1.3
mytbo replied to LeusKapus's topic in Network, Cloud and Web
With curl. See the examples. You can read how curl is used in this forum post and the follow-up links. With best regards Thomas -
With mORMot it can be solved as follows (all tubes for all records, or tubes for record with index): uses mormot.core.base, mormot.core.text, mormot.core.os, mormot.core.variants, mormot.db.rad.ui; function ShowTubesForRecordIndex(pmGrid: TDBGrid; const pmcDBFileName: TFileName; pmDBRecIdx: Integer): Boolean; var docDB: TDocVariantData; begin Result := False; if pmGrid = Nil then Exit; //=> FreeAndNil(pmGrid.DataSource); if docDB.InitJsonFromFile(pmcDBFileName, JSON_FAST_FLOAT) then begin pmGrid.DataSource := TDataSource.Create(pmGrid); var docPath: PDocVariantData := docDB.A['records']._[pmDBRecIdx].O['coin_mech'].A['tubes']; pmGrid.DataSource.DataSet := DocVariantToDataSet(pmGrid.DataSource, Variant(docPath^)); Result := (pmGrid.DataSource.DataSet <> Nil); end; end; function ShowTubesOfAllRecords(pmGrid: TDBGrid; const pmcDBFileName: TFileName): Boolean; var docDB: TDocVariantData; tubes: TVariantDynArray; begin Result := False; if pmGrid = Nil then Exit; //=> FreeAndNil(pmGrid.DataSource); if docDB.InitJsonFromFile(pmcDBFileName, JSON_FAST_FLOAT) then begin var docTubesPath: PDocVariantData; var docRecordsPath: PDocVariantData := docDB.A['records']; for var i: Integer := 0 to docRecordsPath.Count - 1 do begin docTubesPath := docRecordsPath._[i].O['coin_mech'].A['tubes']; for var n: Integer := 0 to docTubesPath.Count - 1 do begin SetLength(tubes, Length(tubes) + 1); tubes[High(tubes)] := Variant(docTubesPath._[n]^); end; end; if Length(tubes) > 0 then begin pmGrid.DataSource := TDataSource.Create(pmGrid); pmGrid.DataSource.DataSet := VariantsToDataSet(pmGrid.DataSource, tubes, Length(tubes), [], []); Result := (pmGrid.DataSource.DataSet <> Nil); end; end; end; Used as follows: var fileName: TFileName := MakePath([Executable.ProgramFilePath, 'DocDB.json']); ShowTubesForRecordIndex(DBGrid, fileName, 0); // ShowTubesOfAllRecords(DBGrid, fileName); I have published an article on topic mORMot DocVariant here (forum Delphi-PRAXIS). Here is the translation into English with Google Translator. The result is not perfect (rather not so good), also some formatting is destroyed, but it is readable. With best regards Thomas
-
I asked Stefan this question a year ago. This was his answer. We can only hope that he will find the time to do this. With best regards Thomas
-
FastReports event signalling finalization of a report output
mytbo replied to TurboMagic's topic in Delphi Third-Party
The event OnAfterPrintReport is fired only after printing. It is not fired during export (unless frxDotMatrixExport). With best regards Thomas -
FastReports event signalling finalization of a report output
mytbo replied to TurboMagic's topic in Delphi Third-Party
Is the answer I gave you on May 21 in forum Delphi-PRAXIS (DE) not helpful? Both links point to an example with source code. With best regards Thomas -
Problem with JSON library "SuperObjects"
mytbo replied to chkaufmann's topic in Network, Cloud and Web
What problems did you have with nested objects? mORMot can serialize almost anything to JSON. And if you use class TSynAutoCreateFields, you don't have to create or destroy the child object(s) yourself. It is enough to write the following: type {$M+} TSubItem = class(TObject) private FSubValue: RawUtf8; published property SubValue: RawUtf8 read FSubValue write FSubValue; end; {$M-} TItem = class(TSynAutoCreateFields) private FValue: RawUtf8; FSubItem: TSubItem; published property Value: RawUtf8 read FValue write FValue; property SubItem: TSubItem read FSubItem; end; var item: TItem; list: TObjectList; begin list := TObjectList.Create; try for var i: Integer := 0 to 1000 do begin item := TItem.Create; item.Value := StringToUtf8('value' + i.ToString); item.SubItem.SubValue := StringToUtf8('subValue' + i.ToString); list.Add(item); end; ObjectToJsonFile(list, '_listData.json'); finally list.Free; end; With best regards Thomas -
Problem with JSON library "SuperObjects"
mytbo replied to chkaufmann's topic in Network, Cloud and Web
In mORMot there are many ways to process JSON. mORMot is at least factor 5 faster than your current solution and more than 20 times faster than Delphi's own classes. A few of several possibilities are: var v: Variant; begin v := _JsonFast('{"splash.annually": "normal"}'); ShowMessage(v.Value('splash.annually')); var doc: TDocVariantData; begin doc.InitJson('{"splash.annually": "normal"}'); ShowMessage(doc.S['splash.annually']); I have published an article on this topic here (forum Delphi-PRAXIS). Here is the translation into English with Google Translator. The result is not perfect (rather not so good), also some formatting is destroyed, but it is readable. With best regards Thomas -
Store a large number of images in the filesystem or in a DB?
mytbo replied to RaelB's topic in Databases
With your requirements I would prefer a SQLite database. There is an article with sample source code on this topic in the DP forum (German part). Here is the translation into English with Google Translator. The result is not perfect, also some formatting is destroyed, but it is readable. With best regards Thomas -
Unable to write array of integers to JSON
mytbo replied to Bart Verbakel's topic in Algorithms, Data Structures and Class Design
The problem is simple. The way you have defined the field in the record, no Rtti information is created. This can be illustrated with the following: var rttiType: TRttiType := TRttiContext.Create.GetType(TypeInfo(TMyRecord)); if rttiType <> Nil then begin var recFieldType: TRttiType; for var field: TRttiField in rttiType.GetFields do begin recFieldType := field.FieldType; if recFieldType <> Nil then ShowMessage(recFieldType.ClassType.ClassName) else ShowMessage('Nil'); end; end; Solution: Explicitly define your own type or use dynamic arrays. type TInt3Array = array[1..3] of Integer; With best regards Thomas -
How to modify the code for $R+
mytbo replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
You are right. Thanks for the explanation. I didn't realize how easy it is to bypass range-checking. With best regards Thomas -
How to modify the code for $R+
mytbo replied to dummzeuch's topic in Algorithms, Data Structures and Class Design
Question for the experts. Is there a reason not to write this way? function BuildDigits(_Digits: UInt16; _Invalids: UInt8): UInt16; var tmp: SmallInt absolute _Digits; begin Dec(tmp, 2048); tmp := tmp * 11; _Digits := (_Digits and $FFFC) or (_Invalids and $03); Result := Swap(_Digits); end; With best regards Thomas -
With mORMot you can do it very easy. uses mormot.core.base, mormot.core.json, mormot.net.client; type TDataRec = packed record Count: Integer; Message: RawUtf8; SearchCriteria: RawUtf8; Results: array of record Value: RawUtf8; ValueId: Integer; Variable: RawUtf8; VariableId: Integer; end; end; var url: RawUtf8 := 'https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/1G1BE5SM8J7207504?format=json&modelyear'; var content: RawByteString := HttpGet(url); if content <> '' then begin var dataRec: TDataRec; if RecordLoadJson(dataRec, content, TypeInfo(TDataRec)) then begin ShowMessage(dataRec.Count.ToString); ShowMessage(Length(dataRec.Results).ToString); for var i: Integer := 0 to High(dataRec.Results) do begin if dataRec.Results[i].Variable = 'Crash Imminent Braking (CIB)' then ShowMessage(dataRec.Results[i].VariableId.ToString); end; end; end; Additional information can be found in this article in Delphi-PRAXIS forum. Here is the translation into English with Google Translator. The result is not perfect (rather not so good), also some formatting is destroyed, but it is readable. With best regards Thomas
-
Best practices for working with a DB accessed via REST API?
mytbo replied to David Schwartz's topic in Databases
You wrote a long text but probably didn't spend a second to follow my links. If you did, what are you missing? I'm happy to take suggestions for further articles. With best regards Thomas