Jump to content

shineworld

Members
  • Content Count

    343
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by shineworld


  1. Hi all,


    First of all, I apologise if what is required is poorly described, but unfortunately I know very little about networks and their knowledge.

    But let's get down to facts.

    In an industrial machine control application, I have inserted a server, a TCP/IP server based on JSON messages, which allows the connection

    of several clients at the same time and enables motor movement commands to be executed or information to be retrieved from the system.

    A client programme connects to the server and from then on can do anything with the device it has connected to.

    At this point, security problems arise, especially for the operator standing at the machine, since a malicious client intruding into the network

    could trigger dangerous operations for the operator standing near the machine and unaware that someone unauthorised has taken control of it remotely.

    Now I have been asked to add a security layer, but as a complete ignoramus on the subject, I deal mainly with compilers of languages and UI environments

    and not with networks, I was wondering how to add a system of certification and authorisation of the client to the server connection.

    For the client I use python while the server is done with Indy 10 using TIdTCPServer.

    Thank you in advance for any suggestions and help.
    Best regards

    Silverio


  2. Hi all.

    Usually I use FMX styles as they are for Firemonkey applications.

    I need to check a style contents with the designer (I do that with VCL styles), but I'm not

    able to find FMX Style Designer in Tools menu.

    Searching with Google seems that FMX Style Designer is available since XE but I cannot find it.

    Have you any idea about ?
     


  3. These are 3 scripts (windows) that I use to:

    1] create requirements.txt file of pip installed packages

    2] download whl packages from requirements.txt

    3] install the whl packages (offline)

     

    A resulting requirements.txt looks like:

    cffi==1.15.1
    cnc-api-client-core==1.3.1
    contourpy==1.0.6
    cryptography==38.0.4
    cycler==0.11.0
    delphifmx==0.1.51
    delphivcl==0.1.40
    fonttools==4.38.0
    kiwisolver==1.4.4
    lxml==4.9.2
    matplotlib==3.6.2
    numpy==1.23.4
    opcua==0.98.13
    opencv-contrib-python==4.6.0.66
    packaging==21.3
    pbr==5.11.0
    Pillow==9.3.0
    pip==22.3.1
    pybind11==2.10.1
    pycparser==2.21
    pyparsing==3.0.9
    PySide6==6.4.0.1
    PySide6-Addons==6.4.0.1
    PySide6-Essentials==6.4.0.1
    PySimpleGUI==4.60.4
    python-dateutil==2.8.2
    pytz==2022.7
    scipy==1.9.3
    screeninfo==0.8.1
    setuptools==65.5.1
    shiboken6==6.4.0.1
    six==1.16.0
    skia-python==87.5
    tendo==0.3.0
    wheel==0.38.3

    Inno Setup script install Python embd and packages in this way;

     

    [Run]
    Filename: {userpf}\{#MyAppName}.python\python.64.exe; Parameters: "-y"; WorkingDir: {userpf}\{#MyAppName}.python; StatusMsg: Unpack Python files...; Flags: runhidden
    Filename: {userpf}\{#MyAppName}.python\python.exe; Parameters: "-m pip install --no-index --find-links offline-packages --force-reinstall --requirement requirements.txt"; WorkingDir: {userpf}\{#MyAppName}.python; StatusMsg: Install Python Offline Packages...; Flags: runhidden
    #endif
    

     

    python-create-requirements.bat

    python-offline-download.bat

    python-offline-install.bat


  4. That's what I do:

     

    1) download python embd version.

    2) added pip

    3) make a backup of this point

    4) used pio to install any package

    5) used pip to create a requirement.txt of installed packages with version

    6) used wheel to download whl of packages from requirements.txt

    7) zipped python embd of point 3

    8) used innosetup to install my exe + python embed + whl packages

    9) during install placed exe in programs,l paced and extracted python in USERAPPDATA and then with script installed offline pip and whl packages.

     

     

    In this mode it's simple to upgrade packages with more fresh without touch python things and end user can install python and packages without a internet connection.

     

     

     


  5. I don't know if can be valid for you, but

    in my Python programs I use Cython to transform the scripts (*.py files) into C code then compiled natively

    and transformed into pyd or .so so as to reduce the possibility of editing them.

     

    Just keep a single "main_dummy.py" that instantiates a class in a "main.pyd" which is followed by all cythonized scripts.


  6. TO BE very SIMPLE, TApplication, with Application instance, is or at least should be a Singleton, because manages the main events loop from Windows.

    You can't have more than ONE...
    It's the Windows structure of any application.

    When you run a program Windows create a process with a main thread which call the delphi main code.
    This main code create Application object which manage the messages loop (Windows is a messages-based OS) and on this
    messages loop manager is implemented all VCL framework, etc...


  7. Some type like this? 

    PS: IsEqualIntegerDynArray placed in method just to test.

    procedure TGCodeEditor.SetGCodeLinePoints(Value: TIntegerDynArray);
    
      function IsEqualIntegerDynArray(const A, B: TIntegerDynArray): Boolean;
      begin
        if Length(A) <> Length(B) then Exit(False);
        Result := CompareMem(@A[0], @B[0], Sizeof(Integer) * Length(A));
      end;
    
    begin
      if not IsEqualIntegerDynArray(FGCodeLinePoints, Value) then
      begin
        FGCodeLinePoints := Value;
        Invalidate;
      end;
    end;

     


  8. That is what I've used....

    procedure TGCodeEditor.SetGCodeLinePoints(Value: TIntegerDynArray);
    var
      F: Boolean;
      L: Integer;
    begin
      F := False;
      L := Length(Value);
      if (Length(FGCodeLinePoints) > 0) and (Length(FGCodeLinePoints) = L) then
        F := CompareMem(@FGCodeLinePoints[0], @Value[0], Sizeof(Integer) * L);
      FGCodeLinePoints := Value;
      if not F then
        Invalidate;
    end;

     


  9. DelphiVCL implements a good subset of VCL objects and related methods/properties/events.
    You can find full Embarcadero VCL documentation on the net: https://docwiki.embarcadero.com/
     

    To know what objects methods/properties/events are implemented and available in DelphiVCL python unit 
    there are two ways (that I know):

    1] Look at sources of P4D in github.
    2] Inspect imported module and every class you want to use:

    Example to inspect VCL objects and Form object:

    P:\>python
    Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    
    >>> import delphivcl as vcl
    >>> dir(vcl)
    ['Abort', 'Action', 'ActionList', 'ActivityIndicator', 'Application', 'BaseBindScopeComponent', 'BaseLinkingBindSource', 
    'BaseObjectBindSource', 'BasicAction', 'BasicBindComponent', 'Bevel', 'BindComponentDelegate', 'BindingsList', 'BitBtn', 
    'Bitmap', 'BoundLabel', 'Button', 'Canvas', 'CheckBox', 'Collection', 'ColorBox', 'ComboBox', 'Component', 'ContainedAction', 
    'ContainedActionList', 'ContainedBindComponent', 'Control', 'ControlBar', 'CreateComponent', 'CustomAction', 'CustomActionList', 
    'CustomActivityIndicator', 'CustomBindingsList', 'CustomControl', 'CustomDrawGrid', 'CustomEdit', 'CustomForm', 'CustomGrid', 
    'CustomLinkControlToField', 'CustomLinkListControlToField', 'CustomLinkPropertyToField', 'CustomMemo', 'CustomNumberBox', 
    'CustomPrototypeBindSource', 'CustomStyleServices', 'CustomTabControl', 'CustomToggleSwitch', 'DateTimePicker', 'DelphiDefaultContainer', 
    'DelphiDefaultIterator', 'DelphiMethod', 'DrawGrid', 'Edit', 'FileOpenDialog', 'Form', 'FreeConsole', 'Graphic', 'GroupBox', 
    'Header', 'IDABORT', 'IDCANCEL', 'IDCLOSE', 'IDCONTINUE', 'IDHELP', 'IDIGNORE', 'IDNO', 'IDOK', 'IDRETRY', 'IDTRYAGAIN', 'IDYES', 
    'Icon', 'Image', 'Label', 'LabeledEdit', 'LinkControlDelegate', 'LinkControlToField', 'LinkControlToFieldDelegate', 
    'LinkListControlToField', 'LinkPropertyToField', 'LinkPropertyToFieldDelegate', 'ListBox', 'MB_ABORTRETRYIGNORE', 'MB_APPLMODAL', 
    'MB_DEFBUTTON1', 'MB_DEFBUTTON2', 'MB_DEFBUTTON3', 'MB_DEFBUTTON4', 'MB_HELP', 'MB_ICONASTERISK', 'MB_ICONERROR', 'MB_ICONEXCLAMATION', 
    'MB_ICONHAND', 'MB_ICONINFORMATION', 'MB_ICONQUESTION', 'MB_ICONSTOP', 'MB_ICONWARNING', 'MB_NOFOCUS', 'MB_OK', 'MB_OKCANCEL', 
    'MB_RETRYCANCEL', 'MB_SYSTEMMODAL', 'MB_TASKMODAL', 'MB_YESNO', 'MB_YESNOCANCEL', 'MainMenu', 'MediaPlayer', 'Memo', 'Menu', 'MenuItem', 
    'Metafile', 'Monitor', 'Notebook', 'NumberBox', 'Object', 'OpenDialog', 'Page', 'PageControl', 'PaintBox', 'Panel', 'PascalInterface', 
    'PascalRecord', 'Persistent', 'Picture', 'Point', 'PopupMenu', 'PrototypeBindSource', 'RadioButton', 'RadioGroup', 'Rect', 'Screen', 
    'ScrollBar', 'Shape', 'ShowMessage', 'Size', 'SpeedButton', 'SpinButton', 'SpinEdit', 'Splitter', 'StaticText', 'StringGrid', 'Strings', 
    'StyleInfo', 'StyleManager', 'StyleServices', 'TabControl', 'TabSheet', 'Timer', 'ToggleSwitch', 'ToolBar', 'ToolButton', 'TrackBar', 
    'VarParameter', 'WinControl', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'bkAbort', 'bkAll', 'bkCancel', 
    'bkClose', 'bkCustom', 'bkHelp', 'bkIgnore', 'bkNo', 'bkOK', 'bkRetry', 'bkYes', 'caFree', 'caHide', 'caMinimize', 'caNone', 'cl3DDkShadow',
     'cl3DLight', 'clActiveBorder', 'clActiveCaption', 'clAppWorkSpace', 'clAqua', 'clBackground', 'clBlack', 'clBlue', 'clBtnFace', 
     'clBtnHighlight', 'clBtnShadow', 'clBtnText', 'clCaptionText', 'clCream', 'clDefault', 'clDkGray', 'clFuchsia', 'clGradientActiveCaption', 
     'clGradientInactiveCaption', 'clGray', 'clGrayText', 'clGreen', 'clHighlight', 'clHighlightText', 'clHotLight', 'clInactiveBorder', 
     'clInactiveCaption', 'clInactiveCaptionText', 'clInfoBk', 'clInfoText', 'clLime', 'clLtGray', 'clMaroon', 'clMedGray', 'clMenu', 'clMenuBar', 
     'clMenuHighlight', 'clMenuText', 'clMoneyGreen', 'clNavy', 'clNone', 'clOlive', 'clPurple', 'clRed', 'clScrollBar', 'clSilver', 'clSkyBlue',
     'clTeal', 'clWhite', 'clWindow', 'clWindowFrame', 'clWindowText', 'clYellow', 'fsBorder', 'fsSurface', 'gdFixed', 'gdFocused', 'gdSelected',
     'mdNearest', 'mdNull', 'mdPrimary', 'mrAbort', 'mrAll', 'mrCancel', 'mrIgnore', 'mrNo', 'mrNoToAll', 'mrNone', 'mrOk', 'mrRetry', 'mrYes', 
     'mrYesToAll', 'ssAlt', 'ssCtrl', 'ssDouble', 'ssLeft', 'ssMiddle', 'ssRight', 'ssShift']
    
    >>> form = vcl.Form(None)
    >>> dir(form)
    ['Action', 'Active', 'ActiveControl', 'ActiveMDIChild', 'ActiveOleControl', 'AfterConstruction', 'Align', 'AlignDisabled', 'AlignWithMargins',
     'AlphaBlend', 'AlphaBlendValue', 'Anchors', 'ArrangeIcons', 'Assign', 'AutoScroll', 'AutoSize', 'BeforeDestruction', 'BeginDrag', 'BeginInvoke',
     'BiDiMode', 'BindMethodsToEvents', 'BorderIcons', 'BorderStyle', 'BorderWidth', 'BoundsRect', 'BringToFront', 'Broadcast', 'Brush', 'CPP_ABI_1',
     'CPP_ABI_2', 'CPP_ABI_3', 'CanFocus', 'Canvas', 'Caption', 'Cascade', 'CheckNonMainThreadUsage', 'ClassInfo', 'ClassName', 'ClassNameIs', 
     'ClassParent', 'ClassType', 'CleanupInstance', 'ClientHandle', 'ClientHeight', 'ClientOrigin', 'ClientRect', 'ClientToParent', 'ClientToScreen',
     'ClientWidth', 'Close', 'CloseQuery', 'Color', 'ComObject', 'ComponentCount', 'ComponentIndex', 'ComponentState', 'ComponentStyle', 'Components',
     'Constraints', 'ContainsControl', 'ControlAtPos', 'ControlCount', 'ControlState', 'ControlStyle', 'Controls', 'Create', 'CreateNew', 'CreateParented',
     'CreateParentedControl', 'Ctl3D', 'CurrentPPI', 'Cursor', 'CustomHint', 'CustomTitleBar', 'DefaultHandler', 'DefaultMonitor', 'DefocusControl',
     'DesignInfo', 'Designer', 'Destroy', 'DestroyComponents', 'Destroying', 'DisableAlign', 'DisableAutoRange', 'Dispatch', 'DisposeOf', 'Dock',
     'DockClientCount', 'DockDrop', 'DockManager', 'DockOrientation', 'DockSite', 'DoubleBuffered', 'DragDrop', 'DragKind', 'DragMode', 'Dragging',
     'DrawTextBiDiModeFlags', 'DrawTextBiDiModeFlagsReadingOnly', 'DropTarget', 'EnableAlign', 'EnableAutoRange', 'Enabled', 'EndDrag', 
     'EndFunctionInvoke', 'EndInvoke', 'Equals', 'ExecuteAction', 'ExplicitHeight', 'ExplicitLeft', 'ExplicitTop', 'ExplicitWidth', 'FieldAddress',
     'FindChildControl', 'FindComponent', 'FlipChildren', 'Floating', 'FloatingDockSiteClass', 'FocusControl', 'Focused', 'Font', 'FormState',
     'FormStyle', 'Free', 'FreeInstance', 'FreeNotification', 'FreeOnRelease', 'GetChildren', 'GetControlsAlignment', 'GetEnumerator', 'GetFormImage', 
     'GetHashCode', 'GetInterface', 'GetInterfaceEntry', 'GetInterfaceTable', 'GetNamePath', 'GetParentComponent', 'GetStyleName', 'GetSystemMetrics', 
     'GetTabControlList', 'GetTabOrderList', 'GetTextBuf', 'GetTextLen', 'GlassFrame', 'Handle', 'HandleAllocated', 'HandleNeeded', 'HasParent', 'Height',
     'HelpContext', 'HelpFile', 'HelpKeyword', 'HelpType', 'Hide', 'Hint', 'HorzScrollBar', 'HostDockSite', 'Icon', 'InheritsFrom', 'InitInstance', 
     'InitiateAction', 'InsertComponent', 'InsertControl', 'InstanceSize', 'Invalidate', 'IsCustomStyleActive', 'IsDrawingLocked', 'IsImplementorOf',
     'IsLightStyleColor', 'IsRightToLeft', 'IsShortCut', 'KeyPreview', 'LRDockWidth', 'Left', 'LoadProps', 'LockDrawing', 'MDIChildCount',
     'MakeFullyVisible', 'ManualDock', 'ManualFloat', 'Margins', 'Menu', 'MethodAddress', 'MethodName', 'ModalResult', 'Monitor', 'MouseInClient', 
     'MouseWheelHandler', 'Name', 'NewInstance', 'Next', 'ObjectMenuItem', 'Observers', 'OleFormObject', 'OnActivate', 'OnAfterMonitorDpiChanged', 
     'OnAlignInsertBefore', 'OnAlignPosition', 'OnBeforeMonitorDpiChanged', 'OnCanResize', 'OnClick', 'OnClose', 'OnCloseQuery', 'OnConstrainedResize',
     'OnContextPopup', 'OnCreate', 'OnDblClick', 'OnDeactivate', 'OnDestroy', 'OnDockDrop', 'OnDockOver', 'OnDragDrop', 'OnDragOver', 'OnEndDock',
     'OnGesture', 'OnGetSiteInfo', 'OnHelp', 'OnHide', 'OnKeyDown', 'OnKeyPress', 'OnKeyUp', 'OnMouseActivate', 'OnMouseDown', 'OnMouseEnter',
     'OnMouseLeave', 'OnMouseMove', 'OnMouseUp', 'OnMouseWheel', 'OnMouseWheelDown', 'OnMouseWheelUp', 'OnPaint', 'OnResize', 'OnShortCut', 'OnShow', 
     'OnStartDock', 'OnUnDock', 'Owner', 'Padding', 'PaintTo', 'Parent', 'ParentBiDiMode', 'ParentCustomHint', 'ParentDoubleBuffered', 'ParentFont',
     'ParentToClient', 'ParentWindow', 'Perform', 'PixelsPerInch', 'PopupMenu', 'PopupMode', 'PopupParent', 'Position', 'PreProcessMessage', 'Previous',
     'Print', 'PrintScale', 'QualifiedClassName', 'Realign', 'RecreateAsPopup', 'RedrawDisabled', 'ReferenceInterface', 'Refresh', 'Release', 
     'RemoveComponent', 'RemoveControl', 'RemoveFreeNotification', 'Repaint', 'ReplaceDockedControl', 'SafeCallException', 'ScaleBy', 'ScaleFactor',
     'ScaleForCurrentDPI', 'ScaleForPPI', 'ScaleRectSize', 'ScaleValue', 'Scaled', 'ScreenSnap', 'ScreenToClient', 'ScrollBy', 'ScrollInView',
     'SendCancelMode', 'SendToBack', 'SetBounds', 'SetDesignVisible', 'SetFocus', 'SetFocusedControl', 'SetParentComponent', 'SetProps', 'SetSubComponent',
     'SetTextBuf', 'Show', 'ShowHint', 'ShowModal', 'Showing', 'SnapBuffer', 'StyleElements', 'StyleName', 'TBDockHeight', 'TabOrder', 'TabStop', 'Tag',
     'TaskbarHandler', 'Tile', 'TileMode', 'TipMode', 'ToList', 'ToString', 'ToTuple', 'Top', 'Touch', 'TransparentColor', 'TransparentColorValue',
     'UndockHeight', 'UndockWidth', 'UnitName', 'UnitScope', 'UnlockDrawing', 'Update', 'UpdateAction', 'UpdateControlState', 'UpdateDesignerCaption',
     'UseDockManager', 'UseRightToLeftAlignment', 'UseRightToLeftReading', 'UseRightToLeftScrollBar', 'VCLComObject', 'VertScrollBar', 'Visible',
     'VisibleDockClientCount', 'WantChildKey', 'Width', 'WindowMenu', 'WindowProc', 'WindowState', '__bound__', '__dir__', '__owned__', 'set_PopupParent']
    >>>

     


  10. 3 hours ago, Rollo62 said:

    @shineworld

    Do you know any more recent repository where the sources were maintained ?

     

    Sincerely I don't know where to find a more updated code.

    I use it for years and for what I need works fine so never tried more updated versions.


  11. In my projects, I use dxgettext with PoEdit pro, which creates an internal net DBase of translated terms,

    so any old translation, made by me or my colleagues can be fastly re-used.
    It also permits auto-translations using Microsoft Translation tools, Deepl (if you have a pro account), etc.

    image.thumb.png.999cc7920a3e1b67c23acc275a4cfca9.png

    It has also a free version so end-customers can translate the programs to their native language with total autonomy,

    because gettext translations are in extern .mo files (but can also be embedded in the EXE if you want).


  12. Thanks for the suggestion I will go and look at it.

    There is another aspect behind the scenes about the choice to use Python.
    In the whole office the only one who uses and knows Delphi and object pascal is me, while my colleagues have been using Python for support projects for a long time already, so creating a framework that is based on Python + extra extensions made ad hoc with Delphi allows me to relieve myself from future work on the Vision compartment to devote myself to something else.

    This is the reason why, when I can, I prefer to create tools that others use and not take a complete, specific project all the way through.

     

    My mathematical background, compared to that of some of the team members, is basic, and they in python will surely be able to solve more elegantly and efficiently cases where my limitations will only get in the way.


  13. Sincerely, I've used an embedded version of Python with minimal packages installed, and the required files are few.

    In Embarcadero GitHub repositories you can find a distro ready to be used.

    No anaconda, conda, or virtual environment.

    Just point to python dll with P4D and the joke is made.

     

    You can also avoid calling a pure py script ad use Embarcadero P4D-Data-Sciences,

    PythonEnvironments and Lightweight-Python-Wrappers and remain always on the Delphi project. 

     

    For markers detection, you can always extract the math and logic of FindContours HougCircles. etc from OpenCV sources,

    as suggested by the name they are open but you have to use something like to NumPy.

     

    I don't like re-invent the wheel when it is already done so I've discarded the idea to re-write all math in pure pascal code,

    although the related math (find counters, HougCircles, etc) is very simple, but very well implemented in OpenCV.    

     

    What they have done in embarcadero with P4D and related tools is very important and allows them not to reinvent hot water by going direct to the use of tools born for scientific purposes.

     

     


  14. Yes, I've used OpenCV features to detect markers but my CNC Vision framework is born and designed to do more other.

    I'm already working on a system which use TensorFlow for more complex image objects detection where Delphi will do things hard to do natively in python.


  15. This, I believe, is due to the fact that the IDE developers, in order to keep the huge amount of threads, timers, etc. needed by the development environment more responsive, have forced the Windows timeCAPS down from the default values (about 50ms) to the lowest possible values, so as to achieve greater accuracy in the timers.

    Some time ago I wasted a lot of hours on this myself.
    I used to run a program from IDE and it was faster than when IDE was not active in memory. As long as it was active, any program would run better, even if not launched from it.

    From here I realized that the IDE was changing something in the operating system.
    I tried to make a program that read timeCAPS with IDE active (they are system and not process) and with IDE active it gave me 1ms, without IDE active 50ms 🙂

    In my applications I force too, obtaining the same times (precision) of timeGetTime and GetTickCount or precision in TThread.Sleep when I run WITH IDE in run o without IDE:

    uses
    	MMSystem;
    
    ; use this option to disable the force of timer precision
    {$DEFINE USES_TIME_BEGIN_END_PERIOD}
    
    var
    {$IFDEF USES_TIME_BEGIN_END_PERIOD}
      TimeCaps: TTimeCaps;
      NeedToChangeTimerPrecsion: Boolean;
    {$ENDIF}
      ... other global values
    
    
    procedure PrecisionTimersStart:
    begin
    {$IFDEF USES_TIME_BEGIN_END_PERIOD}
        // starts high precision timer
        if timeGetDevCaps(@TimeCaps, SizeOf(TTimeCaps)) = TIMERR_NOERROR then
          NeedToChangeTimerPrecsion := timeBeginPeriod(TimeCaps.wPeriodMin) = TIMERR_NOERROR;
    {$ENDIF}
    end;
    
    procedure PrecisionTimersEnd:
    begin
    {$IFDEF USES_TIME_BEGIN_END_PERIOD}
        // stops high precision timer
        if NeedToChangeTimerPrecsion then
          timeEndPeriod(TimeCaps.wPeriodMin);
    {$ENDIF}
    end;
    


    Just call PrecisionTimersStart at program START, eg in dpk code, and call PrecisionTimersStop when the program ends.

×