码迷,mamicode.com
首页 > 其他好文 > 详细

ePx Studio 7.2 常用语法学习真实经典案例

时间:2020-03-21 16:21:43      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:indexof   cal   数据   中文   菜单   comm   addm   gis   view   

1、 使用控件属性作为判断条件:

1 ……
2 if RadioButton2.Checked then
3 begin
4 Statement := this.Replace( Statement,varchar,varchar2 );
5 Statement := this.Replace( Statement,int,number );
6 end;
7 ……

2、 使用控件 Items 集合数量控制循环次数,同时循环与判断相嵌套:

 1 ……
 2 CheckCount := 0;
 3 for I := 0 to CheckListBox1.Items.Count - 1 do
 4 begin
 5 if CheckListBox1.Checked[ I ] then
 6 begin
 7 CheckCount := CheckCount + 1;
 8 end;
 9 end;
10 if CheckCount = 0 then
11 begin
12 this.ShowMessage(没有选择任何需要导入的数据表定义,不能继续操作! );
13 Exit;
14 end;
15 ……

3、 循环与判断综合嵌套应用:

 1 ……
 2 if CanContinue then
 3 begin
 4     TableList := TStringList.Create;
 5     ViewContent := ‘‘;
 6     TableWantDealed := False;
 7     TableIndex := 0;
 8     ProgressBar1.Max := Contents.length;
 9     ProgressBar1.Position := 0;
10     for I := 0 to Contents.length - 1 do
11         beginProgressBar1.Position := I + 1;
12         this.ProcessMessage;
13         Item := Contents.get( I );
14         TableName := VarToStr( Item.get( 表名 ) );
15     if TableList.IndexOf( TableName ) < 0 then
16     begin
17         //向系统表定义插入一行,并创建一张表
18     if Length( ViewContent ) > 0 then
19     begin
20     //创建视图
21     if TableWantDealed then
22     begin
23         CreateSingleView( ViewContent,LastTableName,EnTable,EnView );
24     end;
25     ViewContent := ‘‘;
26     end;
27     //创建表定义及表
28     TableIndex := TableIndex + 1;
29     TableWantDealed := False;
30     ItemIndex := CheckListBox1.Items.IndexOf( TableName );
31     if ItemIndex >= 0 then
32     begin
33         TableWantDealed := CheckListBox1.Checked[ ItemIndex ];
34         CheckListBox1.ItemIndex := ItemIndex;
35     end;
36     if TableWantDealed then
37     begin
38         AddAndCreateSingleTable( Item,TableIndex,TableName,EnTable,EnView );
39         this.PlaySoundRes( 0 );
40     end;
41     LastTableName := TableName;
42     TableList.Add(TableName);
43     end;
44     EnName := Trim( VarToStr( Item.get( 代码 ) ) );
45     CnName := Trim( VarToStr( Item.get( 中文名 ) ) );
46     DispNm := Trim( VarToStr( Item.get( 显示用名 ) ) );
47     if Length( DispNm ) = 0 then DispNm := CnName;
48     if Length( DispNm ) = 0 then DispNm := EnName;
49     Item.set( 显示用名,DispNm );
50     //添加列定义
51     if TableWantDealed then
52     begin
53         AddSingleColumnDefine( Item, TableName, EnTable,EnView );
54     end;
55     if Length(ViewContent) > 0 then ViewContent := ViewContent + ,;
56     ViewContent := ViewContent + EnName +  " + DispNm + ";
57     end;
58     if Length( ViewContent ) > 0 then
59     begin
60         //创建视图
61     if TableWantDealed then
62     begin
63         CreateSingleView( ViewContent,LastTableName,EnTable,EnView );
64     end;
65     end;
66     FreeAndNil( TableList );
67 end;
68 ……

4、 For 与 While 循环嵌套应用:

 1 ……
 2 ProgressBar1.Max:=OldStory.ListParagraphs.Count;
 3 for I := 1 to OldStory.ListParagraphs.Count - 1 do
 4 begin
 5 ProgressBar1.Position:=I;
 6 this.ProcessMessage;
 7 Finished := False;
 8 while not Finished do
 9 begin
10 try
11 CRange := OldStory.ListParagraphs[I].Range;
12 OLevel := CRange.Paragraphs[1].OutlineLevel;
13 if OLevel = 6 then
14 begin
15 OPage := CRange.Information[wdActiveEndPageNumber] - 35;
16 CTitle := Trim(this.Replace(CRange.Text,:(.*?) ,‘‘));
17 CStart := CRange.Start;
18 //紧接着的下一标题
19 for J := I + 1 to OldStory.ListParagraphs.Count do
20 begin
21 NRange := OldStory.ListParagraphs[J].Range;
22 if NRange.Paragraphs[1].OutlineLevel <= 6 then Break;
23 end;
24 NStart := NRange.Start;
25 OldSel.SetRange(CStart,NStart);
26 OldSel.Copy;
27 <此处省略若干行次>
28 this.DeleteFile(SHtmlFile);this.RandomFileWrite(HtmlFile,0,HtmlContent);
29 //选择所有内容(下次粘贴时会覆盖)
30 NewSel.SetRange( 0,99999 );
31 end;
32 Finished := True;
33 except
34 Finished := False;
35 end;
36 end;
37 end;
38 ……

5、 通过函数返回值作为判断条件:

 1 ……
 2 if this.ReadIniSectionValue(ConfigFile,初始化窗口属性,边框) =  then
 3 begin
 4 Form1.BorderStyle := bsNone;
 5 end;
 6 if this.ReadIniSectionValue(ConfigFile,初始化窗口属性,最大化显示) =  then
 7 begin
 8 Form1.SetBounds(0,0,this.ScreenWorkAreaWidth,this.ScreenWorkAreaHeight);
 9 end else
10 begin
11 <此处省略若干行次>
12 end;
13 if this.FileExists(CommandLine.ProjectRoot + \ + ProjectName + .ico) then
14 begin
15 Form1.Icon.LoadFromFile(CommandLine.ProjectRoot + \ + ProjectName + .ico);
16 end;
17 ……

6、 涉及到 JSON 数组与 JSON 对象的循环和判断应用:

 1 ……
 2 MenuKeys := this.ReadIniSectionKeys(ConfigFile,菜单列表);
 3 for I := 0 to MenuKeys.length - 1 do
 4 begin
 5 MKey := VarToStr(MenuKeys.get(I));
 6 MValue := this.ReadIniSectionValue(ConfigFile,菜单列表,MKey);
 7 InfoItems := this.Split(MValue,|);
 8 if InfoItems.Count = 3 then
 9 begin
10 MCaption := InfoItems.Strings[0];
11 MIcon := InfoItems.Strings[1];
12 MModule := InfoItems.Strings[2];Window.registerAMenuIcon(MKey,MCaption,MIcon,MModule);
13 end;
14 end;
15 ……

7、 判断与异常处理语句的综合应用:

 1 ……
 2 var MenuId,Registered,Module,AName: string;
 3 I: Integer;
 4 AParams,AResult: Variant;
 5 const SWP_NOSIZE = 1;
 6 SWP_NOMOVE = 2;
 7 SWP_FRAMECHANGED = $20;
 8 begin
 9 if Identity = OnNavBarMenuClicked then
10 begin
11 MenuId := VarToStr(this.ArrayRead(Params,0));
12 Registered := VarToStr(this.ArrayRead(Params,1));
13 Module := VarToStr(this.ArrayRead(Params,2));
14 if Pos(:,Module) = 0 then
15 begin
16 Module := CommandLine.ProjectRoot + \ + Module;
17 end;
18 Module := this.Replace(Module,\\,SlashFlag);
19 if this.FileExists(Module) or (RunMode=BS) then
20 begin
21 if Registered = 0 then
22 begin
23 Window.registerAModule(MenuId,VarToStr(CommandLine.ProjectRoot));
24 end;
25 Window.activeAModule(MenuId);
26 end else
27 begin
28 this.ShowMessage(模块 + MenuId + 不存在!);
29 end;
30 end else
31 if Identity = GetVariable then
32 begin
33 AName := VarToStr(this.ArrayRead(Params,0));
34 try
35 AResult := Window.htmlVariable(AName);
36 EPX.ClearResults;
37 EPX.AddAResult(AResult);
38 exceptthis.Alert(主框架未定义 htmlVariable 方法.);
39 end;
40 end else
41 if Identity = CallHtmlFunction then
42 begin
43 AName := VarToStr(this.ArrayRead(Params,0));
44 AParams := this.NewArray;
45 try
46 for I := 1 to Params.length - 1 do
47 begin
48 AParams.set(I-1,this.ArrayRead(Params,I));
49 end;
50 finally
51 if Length(AName) > 0 then
52 begin
53 try
54 AResult := Window.htmlFunction(AName,AParams);
55 EPX.ClearResults;
56 EPX.AddAResult(AResult);
57 except
58 this.Alert(主框架未定义 htmlFunction 方法.);
59 end;
60 end;
61 end;
62 end;
63 end;
64 ……

8、 判断与循环在普通函数中的应用:

 1 ……
 2 procedure GenerateProcedureDeclareContent(Struct: Variant;DLines,CLines: TStrings;C
 3 ClassName: string);
 4 var CStruct,CItem,PItem,CParams: Variant;
 5 CName,PName,PType,CDeclare,CCall: string;
 6 I,J: Integer;
 7 begin
 8 //生成过程声明
 9 CStruct := Struct.get(procedures);
10 if not this.VarAssigned(CStruct) then Exit;
11 for I:= 0 to CStruct.length - 1 do
12 begin
13 CItem := CStruct.get(I);
14 CName := VarToStr(CItem.get(name));
15 //函数名称CDeclare := ‘procedure ‘ + CName;
16 if CLines.Count = 0 then
17 begin
18 CCall :=  if MethodName=‘‘ + UpperCase(CName) + ‘‘ then#13#10;
19 end else
20 begin
21 CCall :=  else if MethodName=‘‘ + UpperCase(CName) + ‘‘ then#13#10;
22 end;
23 CCall := CCall +   + CClassName + (Instance). + CName;
24 CParams := CItem.get(params);
25 if this.VarAssigned(CParams) then
26 begin
27 if CParams.length > 0 then
28 begin
29 CDeclare := CDeclare + (;
30 CCall := CCall + (;
31 end;
32 for J := 0 to CParams.length - 1 do
33 begin
34 PItem := CParams.get(J);
35 PName := VarToStr(PItem.get(name));
36 PType := VarToStr(PItem.get(type));
37 if J > 0 then
38 begin
39 CDeclare := CDeclare + ;;
40 CCall := CCall + ,;
41 end;
42 CDeclare := CDeclare + PName + : + PType;
43 if Copy(PType,1,1) = T then
44 begin
45 CCall := CCall + PType + (Integer(Params[ + IntToStr(J) + ]));
46 end else
47 begin
48 CCall := CCall + Params[ + IntToStr(J) + ];
49 end;
50 end;
51 if CParams.length > 0 then
52 begin
53 CDeclare := CDeclare + );
54 CCall := CCall + );
55 end;
56 end;
57 //函数返回值类型
58 CDeclare :=  AddMethod(‘‘ + CDeclare + ‘‘,CallMethod);;DLines.Add(CDeclare);
59 CLines.Add(CCall);
60 end;
61 end;
62 ……

 

ePx Studio 7.2 常用语法学习真实经典案例

标签:indexof   cal   数据   中文   菜单   comm   addm   gis   view   

原文地址:https://www.cnblogs.com/xenli/p/12539759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!