Jump to content
uniGUI Discussion Forums

elGringo

uniGUI Subscriber
  • Content Count

    416
  • Joined

  • Last visited

  • Days Won

    10

elGringo last won the day on April 5

elGringo had the most liked content!

Community Reputation

38 Excellent

About elGringo

  • Rank
    Advanced Member

Recent Profile Visitors

157 profile views
  1. elGringo

    MVC pattern in UniGUI vs traditional coding to form

    Unit testing quite easily maybe done with DUnitX. But "Clean Code" and "Readability" - it is from practice... Which code pattern to use is also good question...
  2. Asked myself - answered myself my workAround procedure TLeftMenu2.OnClickElement(Sender: TObject); function getLeftMenuElement(aID: integer): TLeftMenu2Element; var i: Integer; begin Result := nil; for i := 0 to FOL.Count - 1 do if FOL[i].Tag = aID then begin result := FOL[i]; break; end; end; var leftMenu2Element: TLeftMenu2Element; begin if (Sender is TUniLabel) then leftMenu2Element := getLeftMenuElement((Sender as TUniLabel).Tag); showmessage(leftMenu2Element.lName.Caption); end;
  3. Hi, having 2 classes 1 frame is created on another Second frame on 1 frame there is TUniLabel for example i'm trying to handle onClick event of label in Second frame and assign it like FOL[i].lName.OnClick := OnClickElement; here i have "Invalid type Cast" procedure TLeftMenu2.OnClickElement(Sender: TObject); var i: integer; begin showmessage( // ((Sender as TUniLabel).Parent as TLeftMenu2Element).ClassName // << invalid type Cast ); // end; As Delphi coder I'm doing everything correct, but as UniGUI coder i'm being not so experienced i tried to do things like procedure TLeftMenu2.OnClickElement(Sender: TObject); var i: integer; begin showmessage( // ((Sender as TUniLabel).Parent.Parent).ClassName // ); // end; and on click i have TUniSimplePanel - which is not my class. Is any way to get instance of TLeftMenu2Element - 1 frame on click in 2 frame? Below full code of 2 frames unit uLeftMenu2Element; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIFrame, uniGUIBaseClasses, uniPanel, uniImage, uniLabel; type TLeftMenu2Element = class(TUniFrame) iPic: TUniImage; lName: TUniLabel; procedure UniFrameCreate(Sender: TObject); procedure iPicClick(Sender: TObject); procedure lNameClick(Sender: TObject); private FIsExpanded: boolean; procedure SetIsExpanded(const Value: boolean); { Private declarations } public { Public declarations } property IsExpanded: boolean read FIsExpanded write SetIsExpanded; end; implementation {$R *.dfm} uses uLeftMenu2; procedure TLeftMenu2Element.iPicClick(Sender: TObject); begin if FIsExpanded then begin FIsExpanded := false; iPic.Picture.LoadFromFile('pics/arrowRight16x16.png') end else // if not expanded begin FIsExpanded := true; iPic.Picture.LoadFromFile('pics/arrowDown16x16.png'); end; end; procedure TLeftMenu2Element.lNameClick(Sender: TObject); begin // end; procedure TLeftMenu2Element.SetIsExpanded(const Value: boolean); begin FIsExpanded := Value; end; procedure TLeftMenu2Element.UniFrameCreate(Sender: TObject); begin iPic.Picture.LoadFromFile('pics/arrowRight16x16.png'); lName.Top := trunc(Self.Height / 2 - lName.Height / 2); iPic.Top := trunc(Self.Height / 2 - iPic.Height / 2); end; end. And another class unit uLeftMenu2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIFrame, uLeftMenu2Element, System.Generics.Collections, uniGUIBaseClasses, uniPanel; type TLeftMenu2 = class(TUniFrame) procedure UniFrameCreate(Sender: TObject); procedure UniFrameDestroy(Sender: TObject); private { Private declarations } FOL: TObjectList<TLeftMenu2Element>; procedure OnClickElement(Sender: TObject); public { Public declarations } procedure LoadGoodsTree; // procedure LoadChildren(aID: integer); end; implementation uses FireDAC.Comp.Client, MainModule, uniLabel; {$R *.dfm} procedure TLeftMenu2.LoadGoodsTree; procedure loadNullLevel(); var q: TFDquery; i: integer; h: integer; itemName: string; begin h := 0; q := TFDquery.Create(nil); try with q do begin Connection := UniMainModule.DB.FDConnection; sql.Text := 'SELECT * FROM sewworld_db.goods where idParent is NULL order by sortIndex'; Disconnect(); Open; while not EOF do begin i := FOL.Add(TLeftMenu2Element.Create(Self)); itemName := FieldByName('name').AsString; if itemName.Length > 15 then itemName := itemName.Substring(0, 15) + '...'; FOL[i].lName.Caption := itemName; FOL[i].Parent := Self; FOL[i].Left := 0; FOL[i].Top := h; FOL[i].Show; FOL[i].lName.OnClick := OnClickElement; h := h + FOL[i].Height; Next; end; Close; end; finally q.Free; end; end; begin loadNullLevel(); end; procedure TLeftMenu2.OnClickElement(Sender: TObject); var i: integer; begin showmessage( // ((Sender as TUniLabel).Parent as TLeftMenu2Element).ClassName // ); // end; procedure TLeftMenu2.UniFrameCreate(Sender: TObject); begin FOL := TObjectList<TLeftMenu2Element>.Create; end; procedure TLeftMenu2.UniFrameDestroy(Sender: TObject); begin FOL.Free; end; end.
  4. elGringo

    download file from HTML hyperLink

    Thank you delphiDude !!! I will watch your example. below - decision from DD procedure TMainForm.bTestClick(Sender: TObject); var html: string; begin html := '<a href="#" onclick="return myFunction();">Click Me</a>' + // '<script>' + // 'function myFunction() {' + // // 'replaceThis; ' + // 'ajaxRequest(MainForm.window, "getFile", [ "filePath=12345", "param1=B"]);' + // 'return;' + // '}' + // '</script>'; // FFilePath := f.qFiles.FieldByName('filePath').AsString; UniSession.AddJS(UniHTMLMemo.JSName + '.execCmd(''InsertHTML'',''' + html + ''')'); end; please try to use " instead of ' and '
  5. elGringo

    download file from HTML hyperLink

    the only problem is i have js exception (see picture) my temporary decision is using timer - but it is not Ok decision ! html := '<a href="#" onclick="return myFunction();">' + f.qFiles.FieldByName('fileName').AsString + '</a>' + // '<script>' + // 'function myFunction() {' + // 'replaceThis; ' + // <<<<<<<<<<<<<<<< !!! Here // 'ajaxRequest(MainForm.window, ''getFile'', [ ''filePath=12345'', ''param1=B'']);' + // 'return;' + // '}' + // '</script>'; FFilePath := f.qFiles.FieldByName('filePath').AsString; UniSession.AddJS(UniHTMLMemo.JSName + '.execCmd(''InsertHTML'',''' + html + ''')'); tReplace.Enabled := true; and on timer tReplace.Tag := tReplace.Tag + 1; // inc(tReplace.Tag); if tReplace.Tag = 2 then begin UniHTMLMemo.Text := StringReplace(UniHTMLMemo.Text, 'replaceThis', 'ajaxRequest(MainForm.window, ''getFile'', [ ''filePath=' + FFilePath + ''', ''param1=B'']);', [rfReplaceAll]); tReplace.Enabled := false; end; What could be the problem? You can easily reproduce the case by placing UniHTMLMemo and applying this code from previous message.
  6. elGringo

    download file from HTML hyperLink

    ok, my decision of my problem is <html> <a href="#" onclick="return myFunction();">Link</a> <script> function myFunction() { alert('here'); ajaxRequest(MainForm.window, 'getFile', [ 'filePath=12345', 'param1=B' ]); } </script> </html> and on Server Side if SameText(EventName, 'getFile') then begin showmessage(Params.Values['filePath']); end;
  7. elGringo

    download file from HTML hyperLink

    Yes, file in root/UploadFolder What you suggest?
  8. elGringo

    download file from HTML hyperLink

    ok, Progress, i can do like this in HTML <html> <a href="http://www.google.com" onclick="return myFunction();">Link</a> <script> function myFunction() { document.getElementById(".myDiv").style.flexGrow = "5"; } </script> </html> next step is to learn to request through ajaxRequest from free HTML - is that possible?
  9. elGringo

    download file from HTML hyperLink

    On simple HTTP Server i'am doing smth like this in OnCommandGet begin URIDecoded := TNetEncoding.URL.Decode(ARequestInfo.URI); IsWebPage := false; if IsFileOnServerByURI(URIDecoded, filepath, IsWebPage, WebPageContent) then begin AResponseInfo.ResponseNo := 200; if IsWebPage then AResponseInfo.ContentText := WebPageContent else AResponseInfo.ServeFile(AContext, filepath); end else AresponseInfo.ResponseNo := 404; end; But in UniGUI there is no AContext param...
  10. elGringo

    download file from HTML hyperLink

    hi, looks like simple task, but cannot understand what am i doing wrong having <a href="UploadFolder/TestFile.txt">TestFile.txt</a> on Server doing procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); var uriWinSlash: string; filepath: string; ext: string; begin // ext := ExtractFileExt(ARequestInfo.URI); if ext <> '' then begin uriWinSlash := StringReplace(ARequestInfo.URI, '//', '', [rfReplaceAll]); uriWinSlash := StringReplace(uriWinSlash, '/', '\', [rfReplaceAll]); if uriWinSlash[1] = '\' then uriWinSlash := uriWinSlash.Substring(1); filepath := UniServerModule.StartPath + uriWinSlash; // AResponseInfo.ServeFile(AContext, filepath); UniSession.SendFile(filepath); // << here mistake // Handled := true; end; end; but having mistakes in work of Server if even not downloading... What's up? Any other ideas how to download file from HTML code?
  11. elGringo

    eShop. Sharing. For Delphi Developers

    hi, Bresler! Thank you very much for suggestion. Frankly speaking i don't know from which side to start with ClientAlignment. Because it is absolutely different concept. I'm learning clear ExtJS but i am not too strong in it for the moment. I think i will finish project and will come back to this template to improve it. Thanks, again!
  12. elGringo

    eShop. Sharing. For Delphi Developers

    Yes, but first priority to finish project. I will post here English version in 2 weeks, hope. You just say what you need more in template.
  13. elGringo

    eShop. Sharing. For Delphi Developers

    there is answer on post from other thread i don't waste Farshad Energy ) I do it by mySelf as experiment in name of love to this framwork. No competition to PHP or etc. Just i was interested to turn it to popular tasks. That's all. In success case it could be added as Demo. There are things to complete this template - turn it to clientSide for example. Ruslan, on 06 Apr 2018 - 06:58 AM, said:
  14. elGringo

    Are you more than 40 years old?

    hi, maybe you missed the thread, but answer here... i don't waste Farshad Energy ) I do it by mySelf as experiment in name of love to this framwork. No competition to PHP or etc. Just i was interested to turn it to popular tasks. That's all. In success case it could be added as Demo. There are things to complete this template - turn it to clientSide for example.
  15. elGringo

    eShop. Sharing. For Delphi Developers

    hi, basically 0. set project to mfPage 1. send ajax requests from browser. Main - > ClientEvents -> ExtEvents -> Ext.form.Panel function form.afterrender(sender, eOpts) { var width=Ext.getBody().getViewSize().width; var height=Ext.getBody().getViewSize().height; ajaxRequest(sender, 'formAfterRender', [ 'width='+width,'height='+height]); } function form.resize(sender, width, height, oldWidth, oldHeight, eOpts) { //var browserWidth=Ext.getBody().getViewSize().width; //var browserHeight=Ext.getBody().getViewSize().height; //ajaxRequest(sender, 'formResize', [ 'width='+browserWidth,'height='+browserHeight]); ajaxRequest(sender, 'formResize', [ 'width='+width,'height='+height,'oldWidth='+oldWidth,'oldHeight='+oldHeight]); } 2. On Server Side procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); function getWidthOrHeightValue(aParamValue: string): integer; begin result := -1; if aParamValue = 'undefined' then result := -1 else result := aParamValue.ToInteger(); end; var browserWidth: string; begin //formResize if SameText(EventName, 'formResize') then begin if Params.Values['height'] <> '' then begin pTop.Top := 0; pTop.Left := 0; pTop.Width := Params.Values['width'].ToInteger(); //ajaxRequest(sender, 'formResize', [ 'width='+width,'height='+height,'oldWidth='+oldWidth,'oldHeight='+oldHeight]); pTop.Caption := 'new WxH:' + Params.Values['width'] + 'x' + Params.Values['height'] + ';'// + 'old WxH:' + Params.Values['oldWidth'] + 'x' + Params.Values['oldHeight']; // ScrollBox.Left := 0; ScrollBox.Top := pTop.Height; ScrollBox.Width := Params.Values['width'].ToInteger(); ScrollBox.Height := Params.Values['height'].ToInteger() - 20; // browser height //TopMenu FCurrPage.TopMenu.OnAfterRender( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']) // ); // CurrentPage FCurrPage.Top := 0; FCurrPage.Left := 0; FCurrPage.Width := Params.Values['width'].ToInteger() - 20; // FCurrPage.OnBrowserResize( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']), // getWidthOrHeightValue(Params.Values['oldWidth']), // getWidthOrHeightValue(Params.Values['oldHeight']) // ); // FPagesDM.OnBrowserResize( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']), // getWidthOrHeightValue(Params.Values['oldWidth']), // getWidthOrHeightValue(Params.Values['oldHeight']) // ); end; end; // if SameText(EventName, 'formAfterRender') then begin ScrollBox.Left := 0; ScrollBox.Top := pTop.Height; ScrollBox.Width := Params.Values['width'].ToInteger(); ScrollBox.Height := Params.Values['height'].ToInteger() - 20; // browser height // browserWidth := Params.Values['width']; // FCurrPage.TopMenu.OnAfterRender( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']) // ); // FCurrPage.Top := 0; FCurrPage.Left := 0; FCurrPage.Width := Params.Values['width'].ToInteger() - 20; FCurrPage.OnAfterRender( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']) // ); // FPagesDM.OnAfterRender( // getWidthOrHeightValue(Params.Values['width']), // getWidthOrHeightValue(Params.Values['height']) // ); end; end; for each form, component or something i provide afterRender procedures and onBrowserResize Also i created 3 views in uCommon unit type TView = (smallView, middleView, bigView); and borders between views const leftWidthBorder = 985; const rightWidthBorder = 1024; for example take a look at code of TopMenu unit uTopMenu; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIFrame, uniGUIBaseClasses, uniPanel, uTopMenuElement, System.Generics.Collections, uSearchFrame, uCommon; type TTopMenu = class(TUniFrame) pContent: TUniPanel; procedure UniFrameCreate(Sender: TObject); procedure UniFrameDestroy(Sender: TObject); private FOL: TObjectList<TTopMenuElement>; FNameCount: integer; FSearchFrame: TSearchFrame; FBrowserWidth: integer; procedure SetOL(const Value: TObjectList<TTopMenuElement>); procedure resizeView(aBrowserWidth: integer); procedure setView(aView: TView); { Private declarations } public { Public declarations } procedure OnAfterRender(aWidth, aHeight: integer); procedure OnBrowserResize(aWidth, aHeight, aOldWidth, aOldHeight: integer); procedure PositionElements(aView: TView); property OL: TObjectList<TTopMenuElement> read FOL write SetOL; end; implementation {$R *.dfm} { TTopMenu } uses MainModule; procedure TTopMenu.OnAfterRender(aWidth, aHeight: integer); begin FBrowserWidth := aWidth; resizeView(FBrowserWidth); end; procedure TTopMenu.OnBrowserResize(aWidth, aHeight, aOldWidth, aOldHeight: integer); begin resizeView(FBrowserWidth); end; procedure TTopMenu.setView(aView: TView); begin if aView = smallView then positionElements(smallView) else if aView = middleView then positionElements(middleView) else if aView = bigView then PositionElements(bigView); end; procedure TTopMenu.resizeView(aBrowserWidth: integer); begin if aBrowserWidth > rightWidthBorder then setView(bigView) else if (aBrowserWidth > leftWidthBorder) and (aBrowserWidth <= rightWidthBorder) then setView(middleView) else if aBrowserWidth < leftWidthBorder then setView(smallView); end; procedure TTopMenu.PositionElements(aView: TView); var i: Integer; begin if aView = smallView then begin Self.Visible := false; end else if aView = middleView then begin Self.Visible := true; if FOL.Count > 0 then // 1-st element begin FOL[0].width := 80; FOL[0].Parent := pContent; FOL[0].Top := 0; FOL[0].Left := 0 + 7; FOL[0].lMenuElement.Font.Size := 12; FOL[0].CenterLabel(); end; if FOL.Count > 1 then // other elements begin for i := 1 to FOL.Count - 1 do begin FOL[i].width := 80; FOL[i].Parent := pContent; FOL[i].Top := 0; FOL[i].lMenuElement.Font.Size := 12; FOL[i].Left := FOL[i - 1].Left + FOL[i - 1].Width + 10; // distance between elements FOL[i].CenterLabel(); end; end; FSearchFrame.Top := 11; FSearchFrame.Left := 10 + FOL[FOL.Count - 1].Left + FOL[FOL.Count - 1].Width; end else if aView = bigView then begin Self.Visible := true; if FOL.Count > 0 then // 1-st element begin FOL[0].width := 100; FOL[0].Parent := pContent; FOL[0].Top := 0; FOL[0].Left := 0 + 7; FOL[0].lMenuElement.Font.Size := 13; FOL[0].CenterLabel(); end; if FOL.Count > 1 then // other elements begin for i := 1 to FOL.Count - 1 do begin FOL[i].width := 100; FOL[i].Parent := pContent; FOL[i].Top := 0; FOL[i].lMenuElement.Font.Size := 13; FOL[i].Left := FOL[i - 1].Left + FOL[i - 1].Width + 10; // 10 is distance between elements FOL[i].CenterLabel(); end; end; FSearchFrame.Top := 11; FSearchFrame.Left := 10 + FOL[FOL.Count - 1].Left + FOL[FOL.Count - 1].Width; end; end; procedure TTopMenu.SetOL(const Value: TObjectList<TTopMenuElement>); begin FOL := Value; end; procedure TTopMenu.UniFrameCreate(Sender: TObject); procedure addTopMenuItem(aName, URL: string); var i: integer; begin i := FOL.Add(TTopMenuElement.Create(Self)); FOL[i].Parent := Self; FOL[i].Name := FOL[i].Name + FNameCount.ToString; FOL[i].URL := URL; // inc(FNameCount); FOL[i].lMenuElement.Caption := aName; end; begin FOL := TObjectList<TTopMenuElement>.Create(true); FSearchFrame := TSearchFrame.Create(Self); FSearchFrame.Parent := Self; FNameCount := 0; addTopMenuItem('Акции', UniMainModule.PagesSL[1]); addTopMenuItem('Каталог', UniMainModule.PagesSL[2]); addTopMenuItem('Оплата', UniMainModule.PagesSL[3]); addTopMenuItem('Доставка', UniMainModule.PagesSL[4]); addTopMenuItem('Обучение', UniMainModule.PagesSL[5]); addTopMenuItem('Магазины', UniMainModule.PagesSL[6]); addTopMenuItem('Сервис', UniMainModule.PagesSL[7]); // PositionElements; end; procedure TTopMenu.UniFrameDestroy(Sender: TObject); begin FOL.Free(); end; end.
×