DelphiFan Magazine

Top Menu

Main Menu

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS

logo

DelphiFan Magazine

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS
  • How to add a server application written in UNIGUI to startup?

  • UniGUI Expiry Link Anonymizer

  • UniGUI Add CAPTCHA to the WEB project

  • UniGui. Unique hybrid of Delphi and JS

  • How to transform a blob field into string lines (varchar) in SQL Firebird?

CODE SAMPLESDELPHI
Home›CODE SAMPLES›Example of how to use Intraweb

Example of how to use Intraweb

By admin
November 20, 2020
1932
0
Share:

When asp.net first started, it was also a drag-and-drop control, but then it had MVC and xNext.

Use IntraWeb in another way: The interface is all implemented with html+js+css (some will be dynamically generated with Delphi), and then use js to call Delphi’s method through Ajax.

The template IWForm1.html to be used by the test program:

<!doctype html>
<html>
<head>
<meta charset=”utf-8″ />
<link rel=”stylesheet” href=”IWForm1.css” type=”text/css”/>
<script type=”text/javascript” src=”IWForm1.js”></script>
</head>
<body>
<div id=”div1″>
<a href=”#” onclick=”AjaxFun1(1);”>添加</a>
<a href=”#” onclick=”AjaxFun1(2);”>删除</a>
</div>

<div id=”div2″>{%IWLabel1%}</div>
</body>
</html>

1.Create a Templates folder in the directory where the program is located, and put IWForm1.html in it.
2.Create a wwwroot folder in the directory where the program is located, and put IWForm1.js and IWForm1.css used in the template.
3. The AjaxFun1() method is implemented in IWForm1.js; here the two call parameters are 1, 2
4. IWLabel1 in (%IWLabel1%) is a control added in Delphi, which is used to return data results.

WForm1.js:

function AjaxFun1(n) {
executeAjaxEvent(“&x=”+n, null, “IWCallBack1”, false, null, false);
}

1.The executeAjaxEvent or processAjaxEven method is provided by IntraWeb’s built-in IWLib.js; its third parameter determines that it will call the IWCallBack1 method in Delphi.
2.The parameter received by Delphi will be a TStringList, the above n is the parameter to be passed, and x is the parameter label with arbitrary names.

IWForm1.css:

div { padding: 16px; }
#div2 { background-color: green; color: #fff; }
#IWLABEL1 { font-size: large; }

This is arbitrarily defined; IWLABEL1 corresponds to IWLabel1 added in Delphi.

 

//Place two controls, IWTemplateProcessorHTML1 and IWLabel1, on the new IW main form.

unit Unit1;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWColor, IWTypes, IWVCLComponent, IWBaseLayoutComponent, IWBaseContainerLayout, IWContainerLayout,
  IWTemplateProcessorHTML, IWCompLabel, Vcl.Controls, IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompButton, IWCompEdit;

type
  TIWForm1 = class(TIWAppForm)
    IWLabel1: TIWLabel;
    IWTemplateProcessorHTML1: TIWTemplateProcessorHTML;
    procedure IWAppFormCreate(Sender: TObject);
  public
    procedure DoCallBack1(EventParams: TStringList); //This is the method that IWForm1.js will call; the following also needs to be registered through WebApplication.RegisterCallBack
  end;

implementation

{$R *.dfm}

uses IW.Common.AppInfo; //Get path required

var gPath: string;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  LayoutMgr := IWTemplateProcessorHTML1;          //Associated template (IWForm1.html)
  IWTemplateProcessorHTML1.RenderStyles := False; //Disable IW style settings

  WebApplication.RegisterCallBack('IWCallBack1', DoCallBack1); //Register the callback; js will call the DoCallBack1 method here by specifying the name ("IWCallBack1")

  gPath := TIWAppInfo.GetAppPath + 'Data.txt'; //Path to test file

  if not FileExists(gPath) then //Initialize the test file
  begin
    with TStringList.Create do begin
      Add(DateTimeToStr(Now));
      SaveToFile(gPath, TEncoding.UTF8);
      Free;
    end;
  end;

  IWLabel1.RawText := True; //Specifies to render its content in Html; among several controls with RawText properties, IWLabel1 is found to be the most flexible.
  IWLabel1.StyleRenderOptions.RenderSize := False;     //Since IWTemplateProcessorHTML1.RenderStyles := False; the following should be unnecessary, but not under IE
  IWLabel1.StyleRenderOptions.RenderPosition := False;
  IWLabel1.StyleRenderOptions.RenderFont := False;
  IWLabel1.StyleRenderOptions.RenderZIndex := False;
  IWLabel1.StyleRenderOptions.RenderVisibility := False;
  IWLabel1.StyleRenderOptions.RenderStatus := False;
  IWLabel1.StyleRenderOptions.RenderAbsolute := False;
  IWLabel1.StyleRenderOptions.RenderPadding := False;
  IWLabel1.StyleRenderOptions.RenderBorder := False;
end;

procedure TIWForm1.DoCallBack1(EventParams: TStringList);
var
  List: TStringList;
  x: Integer;
begin
  x := EventParams.Values['x'].ToInteger; //Get the parameters passed by js

  List := TStringList.Create;
  List.LoadFromFile(gPath, TEncoding.UTF8);

  case x of
    1: List.Add(DateTimeToStr(Now));          //The parameter is 1 means add
    2: if List.Count > 0 then List.Delete(0); //The parameter is 2 means delete
  end;

  IWLabel1.Text := List.Text.Replace(sLineBreak, '<br/>'); //Present; 

  List.SaveToFile(gPath, TEncoding.UTF8);
  List.Free;
end;

initialization
  TIWForm1.SetAsMainForm;

end.

The idea is very simple, and some small problems may be encountered in practice, such as:
1. If it is transmitted to the server, the Data.txt will be modified to be writable;
2. When passing Different Languages parameters through executeAjaxEvent, I didn’t find any problems on this machine, but it couldn’t be transmitted to the server. Finally, I wrote an encoding (js) and decoding (Delphi) function; if you need it, you can tell me.
But it’s all small problems.

Tagsdelphidelphi intrawebexample intrawebintaweb
Previous Article

About memory data and JSON

Next Article

Several Delphi programs for obtaining Windows system ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0
  • 0

admin

Related articles More from author

  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi Firemonkey calls functions asynchronously in the main thread (delayed calls)

    November 3, 2020
    By admin
  • CODE SAMPLESDELPHI

    Customize the height of uniGUI Grid header

    October 1, 2020
    By admin
  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi recognizes the battery level of an Android device

    December 10, 2020
    By admin
  • VIDEOS

    Setting up, running and debugging your first MacOS application from Delphi

    September 27, 2020
    By admin
  • CODE SAMPLESDELPHI

    Theme setting for Delphi

    January 1, 2021
    By admin
  • CODE SAMPLESDELPHI

    Work with External program or Files in Delphi

    November 26, 2020
    By admin

Leave a reply Cancel reply

You may interested

  • DELPHITECH NEWS

    Python for Delphi Developers – Part 1 and 2

  • CODE SAMPLESTECH NEWS

    How to modify the maximum number of tcp connections on the windows server

  • CODE SAMPLESDELPHI

    Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

  • LATEST REVIEWS

  • TOP REVIEWS

Timeline

  • January 27, 2021

    How to add a server application written in UNIGUI to startup?

  • January 27, 2021

    UniGUI Expiry Link Anonymizer

  • January 26, 2021

    UniGUI Add CAPTCHA to the WEB project

  • January 26, 2021

    UniGui. Unique hybrid of Delphi and JS

  • January 13, 2021

    How to transform a blob field into string lines (varchar) in SQL Firebird?

Latest Comments

Find us on Facebook

Follow Us on Instagram

logo

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.

About us

  • 660 Pennsylvania Avenue Southeast #100 Washington, DC 20003
  • 0123456789
  • adsdelphi@gmail.com
  • Recent

  • Popular

  • Comments

  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • UniGUI Expiry Link Anonymizer

    By admin
    January 27, 2021
  • UniGUI Add CAPTCHA to the WEB project

    By admin
    January 26, 2021
  • UniGui. Unique hybrid of Delphi and JS

    By admin
    January 26, 2021
  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

    By admin
    August 13, 2020
  • Critical Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

    By admin
    September 4, 2020
  • Setting up the IDE for your first Android Application in Delphi

    By admin
    September 7, 2020

Follow us

Find us on Facebook

© Copyright Delphifan Forum. All rights reserved.