Civil Engineer's Forum-FORUM8
Set this page as your homepage QR

Facebook - FORUM8

Twitter - FORUM8

instagram - FORUM8

YouTube - FORUM8

 Sitemap | Terms of Service | Inquiries | English translation site | Japanese | English | Korean | Vietnam | Francais

1
 Delphi Basic Knowledge Course
NewSeries
 "Concepts of Delphi and basic programming knowledge"
Starting with this issue, we are launching a new online seminar series titled "Introduction to Programming for Civil and Architectural Engineers."
This course is designed for civil and architectural engineers with limited programming experience, and it will clearly explain practical application examples using Delphi programming and SDKs (software development kits). We hope you will find it helpful.


 Introduction

 This online seminar summarizes and concisely introduces the content covered in the book "Introduction to Programming for Civil Engineering and Architecture - Learning VR and Utilizing SDKs for Structural Analysis with Delphi," published by Nikkei BP in November 2010. Through this series of 12 lectures, we will cover everything from the basics of the "Delphi" programming language, which is used to create Windows applications, to applied programming using the FRAME planar SDK for solver utilization in structural analysis, methods for VR development and plugin development using the UC-win/Road SDK, and practical application examples.
 The schedule for future installments is as follows:

 "Programming Introduction for Civil Engineering and Architectural Engineers": Planned series of articles
 ■ Session 1: Introduction to Delphi Fundamentals
        "Concepts of Delphi and basic programming knowledge"
 ■ Second lecture: Structural analysis programming course (part 1)
        "Development utilizing solvers for structural analysis – Utilizing the FRAME(In-Plane) SDK"
 ■ Third lecture: Structural analysis programming course (part 2)
        "Development using solvers for structural analysis – How to use the FRAME(In-Plane) SDK sample program"
 ■ Fourth Structural Analysis Programming Lecture (3)
        "Development of automated solutions for building structure analysis using Mutiframe"
 ■ 5th VR Development Workshop (1)
        "Composition of the UC-win/Road SDK and structure of UC-win/Road"
 ■ Sixth VR Development Workshop (2)
        "Explanation of sample code for practical exercises"
 ■ 7th VR Development Workshop (3)
        "Explanation of sample code for practical exercises"
 ■ Eighth Plugin Development Workshop (Part 1)
        "3D CAD integration plugin"
 ■ Ninth Plugin Development Workshop (Part 2)
        "EXODUS plugin"
 ■ 10th Plugin Development Workshop (3)
        "xpswmm plugin / micro-simulation player"
 ■ Session 11: Plugin Development Workshop (4)
        "OpenGL integration"
 ■ 12th Applied Development Case Study Seminar
        "DS/Railway simulator/Construction machinery man-machine interface"


 Using the Delphi development environment, you can easily create Windows applications. Once you become familiar with programming, you might consider creating slightly more complex programs that can assist you in your work.

 Through this course, we hope that the world of programming, which may have seemed intimidating before, will become a little more approachable and enjoyable. Also, if you are interested in Delphi programming, you might consider delving deeper into the subject by studying the book "Programming Introduction for Civil Engineering and Architecture Engineers."


 Basic knowledge of Delphi

 In this first installment of the series, we will explain the features and concepts of Delphi, as well as basic grammar and fundamental knowledge for program creation.

 Delphi is one of the programming languages used for developing Windows applications. Any standard program that can be developed on Windows can be created using Delphi.

 Furthermore, it possesses VCL (Visual Component Library), which is a class library rebuilt from the Windows API, allowing for relatively easy development of what are typically complex Windows applications. In Windows applications, it's necessary to describe both the Windows classes that represent objects and the procedures that handle messages for those classes; however, Delphi encapsulates a significant portion of this through inheritance. This allows developers to focus primarily on aspects such as "the processing performed when a button is clicked."

 Thanks to the wide variety of available VCL components, Delphi allows you to create screen interfaces and designs quickly. Another notable feature is its short compilation time.


 Basic operations for program creation

■Creating a new project


  1. In Delphi, select [File] -> [New] -> [VCL Forms Application], and then create a new project.

  2. In the tool palette within the displayed window, click on and select the VCL control that you want to place.

  3. When you click on the screen, the selected control will be placed at that location with its default size.

  4. Here, you can set the properties as shown in the table below using the object inspector (located at the bottom left).
    Caption GroupBox1 => Input fields
    Name MyGroupBox
    Left 50
    Top 50
    Width 200
    Height 150


    The settings made in the object inspector are immediately reflected on the screen, allowing for intuitive design (bottom left).
    For example, simply placing a few controls can result in a sophisticated Windows application, as shown in the lower right corner.



■Event handler description

 In Windows, operations such as retrieving input information or closing the screen are performed through actions like clicking buttons with a mouse. The part of the code that describes processes triggered by events, such as "when a button is clicked," is called an "event handler." This section will explain how to write simple event handlers.

 For example, select the control button named "ButtonOK" (left figure) and double-click in the blank space to the right of "OnClick" in the object inspector (right figure).


This will display an area where you can implement the code that executes when this button is clicked on the unit. Within the "begin" and "end;" statements, you should write the processing logic to be executed when the button is clicked, as follows.

procedure TForm1.ButtonOKClick(Sender : Tobject);
begin
end;

For example, if you write "Close;" in the description, clicking this button at runtime will close the screen.

procedure Tform1.ButtonOKClick(Sender : Tobject);
begin
  Close;
end;

Once you have finished writing the necessary event handlers, select "Run" from the "Execute" menu in the menu bar to compile the code.
When compilation completes successfully, the program will be executed.


 Source code structure and data types

 Here, we will explain the structure of the source code and the data types used, which are necessary when writing source code.
Since this forms the foundation of programming, it's important to understand it thoroughly.


■Source code file structure and unit organization

 Delphi source code primarily consists of 3 types of files.
  • Project file (.dpr)
    This is the main source file for the project. Usually, Delphi automatically handles the contents of the source file.

  • Unit file (.pas)
    This is the file where the actual processing is defined. Source code is primarily written in this file.

  • Form file (.dfm)
    This file contains information such as screen design details. Typically, Delphi automatically processes the content of this file.


■ Unit file structure

 The source code is mainly written in unit files. A unit is divided into 4 main parts: the interface section, the implementation section, the initialization section, and the termination processing section.

Unit files begin with a "unit" header. The space next to "unit" represents the file name, and it should not be directly modified within the IDE editor. Furthermore, unit names cannot be duplicated within the same project, even if they are located in different directories. This is also true for project file names.


■Variables and constants

 To work with values in a program, you use variables or constants. Variables and constants are like containers that hold values. Unlike mathematical expressions, they can be written as follows:

A := A + 1;

 This example demonstrates the process of adding 1 to the original value of variable A and then assigning the result back to variable A. Variables can have their values changed during program execution, while constants maintain a fixed value throughout the program's execution.


■Data types

 In Delphi, data used in programs have types (which are names that define the type of data). When using variables or constants in a program, it is necessary to specify their types, and the type determines what kind of data can be stored in the variable and what operations can be performed on it. Delphi is a strict language when it comes to type checking, so it's important to pay attention because if you use the wrong type, the intended operation may not work. As for basic data types, it is sufficient to remember the following 4:
  • Integer type
    This is used when working with integers. To assign the value 100 to an integer variable named A, you would write it as follows.

    A:=100;

  • Floating-point (double)
    It is used for handling real numbers. While it can include decimal places, the number of digits is finite, so it cannot store values with perfect precision. To assign the value 123.456 to a real-number variable named "B", you would write something like this:

    B:=123.456;

  • String type
    Strings are used to handle character sequences. To assign the characters "Hello" to a string variable named C, you would write something like this.

    C := 'Hello';

  • Boolean type
    Boolean types are used when assigning true or false values. These values, which can be represented as True and False, are used to determine whether something is correct or incorrect, and also in the decision-making processes of control statements, which will be described later.


■ Scope

 The scope refers to the region within a program where identifiers such as variable names and function names can be accessed. Identifiers like variable names and function names can only be used within their declared scope. Furthermore, the scope is determined by the location of the declaration.


■Sentences and comment sentences

 A statement refers to an element that constitutes a program. A single statement is separated by a semicolon.

A := 1;

Comment lines do not affect the actual operation of the program, but they are used to write text that you want to include as annotations within the source code. In Delphi, comments are written by using 2 forward slashes ("/") followed by the comment text, such as "//comment".


■ Procedures and Functions

 Procedures and functions are self-contained sets of statements that can be called from other parts of a program.
Procedures and functions are also called routines. A function is a routine that returns a value when executed, while a procedure can be considered a routine that does not return a value.

procedure procedure_name(parameter1; parameter2; ...);
begin
end;

 The procedure is declared as follows: "procedure" declares the procedure, and the processing to be performed is written between "begin" and "end;".

procedure procedure_name(parameter1; parameter2; ...);
begin
end;

 Functions are declared as follows: The `function` keyword declares the function, and the code to be executed is written between `begin` and `end;`. Since a function returns a value, its return type must also be declared.

function function_name(parameter1; parameter2; ...): return_type;
begin
end;


■Parameters

 Many procedures and functions have parameter lists. A parameter list consists of a series of parameter declarations separated by semicolons, enclosed in parentheses. Before each declaration, one of the keywords `var`, `const`, or `out` can be placed. The keyword `var` indicates a variable parameter, `const` indicates a constant parameter, and `out` indicates an out parameter. If no keyword is specified, it represents a value parameter, where the value is passed to the procedure or function.

 By describing the parameters as follows, you can pass the vertical and horizontal values of a rectangle as parameters to a function, and the function will return the area of the rectangle.

function SquareRectangle( height, width : double ):double;
begin
  result := height * width;
end;



 Components and events

 "Components" are like the building blocks that make up a program. Delphi provides many components, and by utilizing these, you can create programs efficiently without putting in too much effort.

■Component types

 Delphi includes components that can be broadly categorized into visual and non-visual components. The former is a library of classes for standard Windows visual controls such as buttons, forms, labels, and edit boxes. These are used to build graphical user interfaces (GUIs) and are displayed visually during program execution. The latter consists of non-visual components such as network communication methods and timer components, which are not displayed on the screen.

■Properties

 A property refers to an attribute of a component, and settings such as behavior and appearance can be configured. For example, the Visible property allows you to specify whether or not a component should be displayed during program execution.

■Method

 Components have various "methods" in addition to properties. A method refers to a procedure or function defined within a class. Since components are defined as classes, the procedures and functions used by the component become methods.

■Events

 An event refers to an action or occurrence that is detected by a program. In Windows applications, events typically include actions such as when a button is pressed or the mouse is clicked, and the program processes these events accordingly.

 When using components, you can set event handlers for events in the object inspector. An event handler refers to a procedure that is executed in response to an event. For example, let's specify a process that displays a message when a button is clicked.

  1. Ensure that the target button is selected.


  2. Click on the "Event" tab within the Object Inspector to select it.

  3. Select the OnClick event to be used when a component is clicked, and double-click the input field.


  4. An event handler named "Button1Click" is automatically created, so you should write the message display processing logic here.


With that, the series of operations is complete. By performing these simple steps, a program is created that displays the message "Button pressed" when a button is clicked. Since most of the processing is done on the Delphi side, you can create the program by simply writing the code for the part that actually displays the message.



 Let's try creating a simple application

 In this section, we will create an application with text editor functionality similar to "Notepad" by arranging components. The specifications of the application are as follows:
 
  [Execute] - [Program]: A menu that allows you to input and edit characters in a text format, providing available operations
  [File] Menu: New, Open, Save, Save As, Print, Exit
  [Format] menu


■Menu design creation


  1. First, from the tool palette, place the following components onto the form.

      ・TMemo

      ・TMainMenu

      ・TStatusBar

      ・TOpenDialog

      ・TSaveDialog

      ・TPrintDialog

      ・TFontDialog

  2. To implement a menu, right-click on the "MainMenu1" component that is placed on the Form and launch the "Menu Designer."


  3. To register an item in the menu designer at the desired location, click on that location and then enter the name in the Caption property of the object inspector; the same name will then appear in the menu.

  4. First, enter "File" in the Caption property and press the Enter key. This will display the word "File" on both the menu designer and the form. Then, register the menu items according to the specifications mentioned earlier. If you want to set a separator line, entering "- (half-width hyphen)" in the Caption field will automatically convert it into a separator line.


■New creation menu

 To implement the processing that occurs when a menu item is clicked, you need to create a method (function) that performs the desired action and assign it to the OnClick event of the menu. Delphi 2010 automatically handles this process. In the Object Inspector, select "Events" and double-click "OnClick," which will switch the screen to the unit view and prepare the source code for editing. You should enter the following in the relevant section:

Memo1.Lines.Clear;

 This is a command that clears the string displayed in the memo component. Furthermore, it's necessary to determine whether the memo field has been edited and then confirm whether to save the changes; however, this process can be shared with other menu items such as "Open" and "Exit," which will be explained later.

■ Open Menu

 Similar to creating a new menu item, you need to create an OnClick event for the "Open" menu. The process of opening requires 2 steps.
  • Select the file to open
  • Load the selected file

 This application only supports text files for file selection. Therefore, the following must be registered in the Filter property of the OpenDialog: If you want to register multiple file formats, separate them with semicolons.

Text files; *.txt;

Here, we will describe it as follows.

if OpenDialog1.Execute then
begin
  if not FileExists( OpenDialog1.FileName ) then
  begin
    ShowMessage('No File!');
    Exit;
  end;
  memo1.Lines.LoadFromFile( OpenDialog1.FileName );
end;

The process involves selecting a file using the OpenDialog, and if the file exists, it loads that file. Similar to the "New" menu option, measures are needed in case the memo field has been edited, but I will omit those details for now.


■Save menu

 To perform the save operation, call the SaveToFile function of the Lines property of the Memo1 property. Create an OnClick event for the [Save] menu and write the following code:

if SaveDialog1.Execute then
begin
  if FileExists( SaveDialog1.FileName ) then
    if MessageDlg('File aleady exists. Save now?', mtWarning,
                       [mbYes, mbNo], 0, mbYes) = mrYes then
    begin
      Memo1.Lines.SaveToFile( SaveDialog1.FileName );
    end;
end;

Similar to the OpenDialog, the SaveDialog also allows you to set the Filter property.

Text file (*.txt) | *txt

When you register the above description, the file types displayed in the dialog will be limited to text format. Additionally, if you register the extension you want to suggest (in this case, "txt") in the DefaultExt property, it will automatically provide suggestions.

Similarly, we will implement features such as "Save As," "Print," "Application Settings," and the "Format" menu. For more details, please refer to the book "Programming Introduction for Civil Engineering and Architecture Engineers," which I mentioned at the beginning; if you are interested, please take a look.

Next time, we will have "Structural Analysis Programming Lecture (1)". We plan to explain practical application examples of programming using the FRAME in-plane SDK for solver utilization in structural analysis, so please look forward to it.


Announcement of paid seminars

 Introduction to Programming for Engineers Seminar CPD Accredited
• Date and time January 21, 2011 (Friday), 9:30 AM to 3:00 PM
• Course fees Price for 1 person: 15,750 yen (including tax)
• This is the main venue FORUM8 Tokyo headquarters, GT Tower seminar room
※TV conferencing systemThe event will be held simultaneously in Tokyo, Osaka, Nagoya, and Fukuoka


     
Previous page    Index    Next page
(Featured in the January 2011 issue of Up&Coming)
Go back
Up&Coming

FORUM8


Contact information




■ [User Introductions]
sugiko Corporation, Technical Sales Department
Scaffolding Safety Consulting Department

Mie University, Graduate School of Engineering
Seika Digital Image Co., Ltd.
Infranet Co., Ltd.






>> Product comprehensive catalog


>> Premium membership services
>> Financial support

Recently released products
■ Electrical Media Delivery Support Tool Version 19
■ Retaining wall design, 3D reinforcement detailing, Version 26
■ Bridge Maintenance Plan System Version 7
■ Calculation for concrete slab placement (compliant with R7/H29 road standards), Version 2

Campaign in progress
■ Within 2 years of release, enjoy a 30% discount plus 30,000 FPB points back
■ Smart download
■ Design Festival 2026, exclusive for visitors
■ Drone school discount

Seminar and event calendar
Upcoming seminars
11/26  Metavernia F8 VPS experience
11/27  Introduction to Structural Analysis
12/2  Engineer programming
  Introduction to yoga experience
12/3  DesignBuilder experience
12/4  Reinforced concrete foundation

Software/Support Services
VR software(Virtual reality)
《UC-win series》
Road simulator
• Driving simulator
• Micro-simulation
Evacuation analysis and simulation
>> Other VR software
FEM analysis software
・3-dimensional plate dynamic nonlinear analysis
・2-dimensional dynamic nonlinear analysis
・A comprehensive finite element analysis system
>> Other FEM analysis software
Civil engineering, architecture, and design software
《UC-1 Series》
・Structural analysis/cross-section
Bridge superstructure
・Bridge substructure components
Foundation work
Temporary construction
Road construction and earthworks
・Harbors
・Hydraulic engineering
・Subsurface investigation and analysis
・CAD/CIM systems, construction accounting
• Maintenance and management, earthquake risk
Architecture
・Ships/Evacuation
>> Other civil engineering, construction, and design software
Cloud
《Supercomputer Cloud®》
・Supercomputer cloud services
《VR-Cloud®》
・Real-time VR system
Analytical support services/support
・UC-win/Road support system
・Design verification support service
・Engineer's Studio® analysis support
・Ground investigation analysis support services
・EXODUS/SMARTFIRE analysis support
・XPSWMM analysis support services
Building energy simulation
• 3D laser scanning and modeling
・3D modeling services
• 3D report and drawing services
>> Other support services
Various solutions
Seismic resistance assessment/analysis
・Design of steel bridges
・New bridge construction methods
Architectural design
・Local governments
・Medical VR systems
・Parking solutions
・ECO solutions
>> Other solutions