Jump to content

Rolf Fankhauser

Members
  • Content Count

    22
  • Joined

  • Last visited

Community Reputation

1 Neutral

Technical Information

  • Delphi-Version
    Delphi 10.3 Rio

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Rolf Fankhauser

    How to use Open XML SDK in C++Builder

    Ok, I found Bruno Sonnino's Blog. He shows how to create OpenXML files in Delphi without using the SDK but directly generating the XML code (but it looks rather cumbersome...). I think that should also be possible in C++Builder. So, many thanks to Bruno for this tutorial and sharing the code !! But hints how to use the SDK in C++Builder would be still appreciated...
  2. Rolf Fankhauser

    How to use Open XML SDK in C++Builder

    I would like to use Open XML SDK in C++Builder. I found instructions, docs and forums only for VS C++. I tried the Direct Office library for Delphi but it doesn't support C++Builder. Thanks in advance for any hints!
  3. Hi, I generate in my application dynamically svg code using a javascript version of GraphViz (viz.js). The nodes are created as follows: <g class="node" id="node1"><title>B Regen</title> <polygon fill="none" stroke="black" points="63.9539,-396 0.0460627,-396 0.0460627,-360 63.9539,-360 63.9539,-396" /> <text font-family="Times,serif" font-size="14" text-anchor="middle" x="32" y="-373.8">B Regen</text> </g> Because I want to show some data of the objects (nodes) on MouseOver I changed the innerText of <title> (which is shown as hint by default by the browser) by the following C++ code: // helpers for interface reference counting // could alternatively use TComInterface instead of DelphiInterface typedef DelphiInterface<IHTMLDocument3> _di_IHTMLDocument3; typedef DelphiInterface<IHTMLElement> _di_IHTMLElement; typedef DelphiInterface<IHTMLElementCollection> _di_IHTMLElementCollection; typedef DelphiInterface<IHTMLWindow2> _di_IHTMLWindow; // Get Data: _di_IHTMLDocument3 doc = CppWebBrowser1->Document; _di_IHTMLElement elem; _di_IHTMLElementCollection collection; _di_IHTMLWindow window; long len; TVariant value; // only for testing OleCheck(doc->getElementById(WideString("svg"), &elem)); if (elem) { elem->getAttribute(WideString("viewBox"), 2, &value); ShowMessage("viewBox: " + value); } // fill the title tags with data to show on Mouse over: OleCheck(doc->getElementsByTagName(WideString("title"), &collection)); collection->get_length(&len); //ShowMessage("Collection length: " + IntToStr(len)); //ShowMessage(Commands->Text); WideString tmp, tmp2; int line; for (long i = 0; i < len; ++i) { TVariant name = i; TVariant index = 0; DelphiInterface<IDispatch> disp; if(SUCCEEDED(collection->item(name, index, &disp))) { DelphiInterface<IHTMLElement> element; if( SUCCEEDED(disp->QueryInterface(IID_IHTMLElement, (LPVOID*)&element))) { element->get_innerText(&tmp); //reading element name line = FindElementInMemo(Commands, Trim(tmp)); //finding the element in a memo if (line != -1) { tmp2 = ExtractParameters(Commands->Strings[line]); //extracting the data to show //if (tmp != WideString("Output")) { if (tmp2 == WideString("")) tmp2 = WideString("a<br>b"); //test to format the data on two lines OleCheck(element->put_innerHTML(tmp2)); //replace the original text of the element name by the element data } } } } All is working but the text is not shown on multiple lines. ExtractParameters returns one line, so I made a test by creating constant data of 2 lines by "a<br>b". I tried with put_innerText and put_innerHTML but without success. Any idea why this doesn't work? Could I define a separate event handler for onmouseover using doc->execScript ? Thanks, Rolf
  4. Did you try to generate import libraries with mkexp?
  5. In my application I generate a SVG graphic in a TCppWebBrowser by providing GraphViz dot language code that is converted to SVG by a JavaScript version of GraphViz viz.js. File _test.html shows the original HTML page (dot code and JavaScript code) that produces the SVG output shown in file test.html. In the form with the TCppWebBrowser component I added some buttons to zoom in, out and reset to 100%: //--------------------------------------------------------------------------- void __fastcall TFormViewer::btZoomInClick(TObject *Sender) { ZoomFactor *= 1.1; OleVariant ZoomFac = int(ZoomFactor); CppWebBrowser1->ExecWB(63, OLECMDEXECOPT_DONTPROMPTUSER, ZoomFac, 0); } //--------------------------------------------------------------------------- void __fastcall TFormViewer::btZoomOutClick(TObject *Sender) { ZoomFactor *= 0.9; OleVariant ZoomFac = int(ZoomFactor); CppWebBrowser1->ExecWB(63, OLECMDEXECOPT_DONTPROMPTUSER, ZoomFac, 0); } //--------------------------------------------------------------------------- // void __fastcall TFormViewer::btResizeClick(TObject *Sender) { ZoomFactor = 100; OleVariant ZoomFac = int(ZoomFactor); CppWebBrowser1->ExecWB(63, OLECMDEXECOPT_DONTPROMPTUSER, ZoomFac, 0); } This works fine but for huge networks with hundreds of elements I would like to zoom to a specific element by name (in test.html e.g. to "HE M15". My idea is to change the viewBox attribute of the svg object. So, I need to find the element with the specific name (e.g. "HE M15"), read the x, y coordinates of the text and change the viewBox accordingly. Would this be possible by IHTMLWindow2::execScript (JavaScript code) or other tools to access the DOM... or would it be easier to save the html page, load it in a StringList, search the element and coordinates there and change the viewBox attribute, save the file and load it into the TCppWebBrowser component again? __test.html test.html
  6. Rolf Fankhauser

    What about additional free open source C++ libraries on GetIt ?

    @oliwe: I have already encountered VTK when I worked shortly with Paraview using some CFD software and VisIt (3D visualization of MRI slices) and recently when I was looking for a graph drawing library. Many programs and libraries are built on top of VTK. At the moment I use Graphviz in C++Builder for drawing graphs/networks. But I use a Javascript implementation of Graphviz viz.js. There is also a COM library WinGraphviz that could be used.
  7. Rolf Fankhauser

    What about additional free open source C++ libraries on GetIt ?

    Here is an example for install documentation of NLopt It would be nice to have more such documentation for important free open source libraries (with a license allowing commercial use). Installation over GetIt would be perfect but not a must. Installing documentation would be enough.
  8. Rolf Fankhauser

    Timer game delphi 7

    Please find attached unit StopWatch for Delphi 7 (StopWatch.pas) This is from Zarko Gajic, possibly not exactly identical to that from System.Diagnostics.
  9. I tried to install and use OpenCV under C++Builder 10.3.3 (see stack overflow), until now without success. Wouldn't it possible that Embarcadero could make this important library available via GetIt or at least provide a short installation tutorial with working dll's and import libs ? For Delphi there is a project on GitHub (Delphi-OpenCV) but it's an old version and I don't know if it can be used in C++Builder. At the moment there are 15 C++ libraries available on GetIt. Not very much compared to MS VC (ca. 800) . I don't need 800 but it is rather frustrating if I see an interesting library but install/compiling instructions only for GCC or MS VC or just precompiled packages only for MS VC.. Some libraries are easier to install than OpenCV, e.g. NLopt for non-linear optimization that I tested. Would also be a candidate for GetIt. Maybe I belong to a minority of RAD Studio users because I need many mathematical and scientific libraries and these libraries have low priority for Embarcadero. Then let me know...
  10. Rolf Fankhauser

    Problems using embedded python package for Windows

    I installed the PyQt5 package: ...\python> cd Scripts ...\python\Scripts> pip install PyQt5 Now matplotlib is working with GUI because there is now Qt as a GUI backend. The window doesn't look really native, Tk looks nicer.
  11. Rolf Fankhauser

    Problems using embedded python package for Windows

    I now installed the newest version with python 3.9.4. There is a file python39._pth (I checked it: Indeed, the python35 package didn't have a file python35._pth) So, I changed all according to the instructions. I installed numpy and matplotlib but when I try matplotlib from the command prompt and want to plot I get the following warning: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. Only this backend "agg" is installed, no others. If I try to install Tkinter I get the same error as before with the python35 package: ERROR: Could not find a version that satisfies the requirement Tkinter ERROR: No matching distribution found for Tkinter Can I use a Delphi window as backend? Saving the plot as png or svg and display it in Delphi would be a workaround but rather complicated.
  12. Rolf Fankhauser

    Problems using embedded python package for Windows

    Hello SwiftExpat Thanks for the links. I already know the first link. The problem is that I have no such file python35._pth. I will check the other link and possibly download and install the embeddable distribution again.
  13. Rolf Fankhauser

    Poor performance of Python script

    Thanks a lot !! This reference counting is annoying !! Thanks for the link, I will study the article. I supposed that ExtractPythonObjectFrom does increment the reference count. I corrected my code with your above suggestions. You forgot to remove PythonEngine1: var PyInput := PE.PythonEngine1.PyFloat_FromDouble(Input); Performance didn't change
  14. Rolf Fankhauser

    Poor performance of Python script

    Ok, 1 mio iterations in 325 ms (average). That's close to the C-API version and 10 times slower than compiled. That is usable. That's the code: procedure TForm1.btRunScriptedClick(Sender: TObject); var i, i_end: integer; start, stop: TDateTime; start2, stop2: cardinal; sw : TStopWatch; script: TStringList; PyFunc, PyValue, PyArgs: PPyObject; begin sw := TStopWatch.Create; script := TStringList.Create; Memo2.Lines.Append(''); Memo2.Lines.Append('loop started with python script, 1 mio iterations!'); try i_end := 1000000; start := Now; start2 := GetTickCount; sw.Start; script.LoadFromFile('loop_function.py'); PythonEngine1.ExecStrings(script); PyFunc := ExtractPythonObjectFrom(MainModule.calc_outflow); PyArgs := PythonEngine1.PyTuple_New(1); for i:=1 to i_end do begin Input := Random * 10.0; //PyValue := PythonEngine1.PyLong_FromLong(Input); integer version PyValue := PythonEngine1.PyFloat_FromDouble(Input); PythonEngine1.PyTuple_SetItem(PyArgs, 0, PyValue); PyValue := PythonEngine1.PyObject_CallObject(PyFunc, PyArgs); //Output := PythonEngine1.PyLong_AsLong(PyValue); integer version Output := PythonEngine1.PyFloat_AsDouble(PyValue); //Memo2.Lines.Append('Input: ' + IntToStr(Input) + ', Output: ' + IntToStr(Output)); end; stop := Now; stop2 := GetTickCount; sw.Stop; if sw.IsHighResolution = true then Memo2.Lines.Append('Is high resolution!') else Memo2.Lines.Append('Is not high resolution!'); Memo2.Lines.Append(''); Memo2.Lines.Append('Time by Now to run loop: ' + FloatToStr(RoundTo((stop - start)*24*3600*1000, -3)) + ' ms'); Memo2.Lines.Append('Time by GetTickCounts to run loop: ' + IntToStr(stop2 - start2) + ' ms'); Memo2.Lines.Append('Time by StopWatch to run loop: ' + IntToStr(sw.ElapsedMicroseconds) + ' us'); Memo2.Lines.Append('Time by StopWatch to run loop: ' + IntToStr(sw.ElapsedNanoseconds) + ' ns'); finally { with PythonEngine1 do begin if Assigned(PyValue) then Py_DECREF(PyValue); if Assigned(PyArgs) then Py_DECREF(PyArgs); if Assigned(PyFunc) then Py_DECREF(PyFunc); end; } sw.Free; script.Free; end; end; I have some problems with dereferencing the PPyObjects. Therefore I removed them. I got an AV when I run the loop multiple times with dereferencing. But I don't understand why. Without dereferencing I had no problems to run the loop multiple times.
  15. Rolf Fankhauser

    Poor performance of Python script

    I used the following code (not complete) to call the function in C++Builder: PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue, *pType, *pTraceback; int i; ... pArgs = PyTuple_New(1); ... for (int j = 0; j < j_end; j++) { i = random(10); pValue = PyInt_FromLong(i); PyTuple_SetItem(pArgs, 0, pValue); pValue = PyObject_CallObject(pFunc, pArgs); } I guess that PPyObject (Delphi) is equivalent to PyObject (C) With ExtractPythonObjectFrom(MainModule.calc_outflow) I would define pFunc, right? I will try it...
×