cwebutils.pas
来自「Delphi深度探索,Delphi深度探索(第二版)」· PAS 代码 · 共 84 行
PAS
84 行
{-----------------------------------------------------------------------------
Unit Name: CWebUtils
Author: hubdog(陈省)
Purpose: 常用的Web例程
BeginDate: 2002-7-1
History:
-----------------------------------------------------------------------------}
unit CWebUtils;
interface
uses DB,Classes,SysUtils,IWInit, IWTypes,IWAppForm, IWCompListbox;
//释放当前界面,显示下一个界面
procedure Move(AFormClass: TIWAppFormClass);
//获取数据字典
function GetDataDicList(DS:TDataSet;const KeyName, ValueName:String):TStrings;
//用数据字典填充进ComboBox
procedure FillValueToCombo(ACombo:TIWComboBox;AStrings:TStrings);
//获取ComboBox的Value所对应的Key
function GetKeyFromCombo(ACombo:TIWComboBox; AStrings:TStrings):string;
//根据Value设定ComboBox
procedure SetComboKeyByValue(ACombo:TIWComboBox; Value:string; AStrings:TStrings);
//根据Value获得Name
function GetValueByKey(AStrings:TStrings; Value:string):string;
implementation
function GetValueByKey(AStrings:TStrings; Value:string):string;
var
I:Integer;
begin
Result:='';
for I:=0 to AStrings.Count-1 do
if AStrings.Values[AStrings.Names[I]]=Value then
Break;
Result:=AStrings.Names[I];
end;
procedure SetComboKeyByValue(ACombo:TIWComboBox; Value:string; AStrings:TStrings);
begin
ACombo.ItemIndex:=ACombo.Items.IndexOf(GetValueByKey(AStrings, Value));
end;
function GetKeyFromCombo(ACombo:TIWComboBox; AStrings:TStrings):string;
begin
Result:=AStrings.Values[ACombo.Text];
end;
procedure FillValueToCombo(ACombo:TIWComboBox;AStrings:TStrings);
var
I:Integer;
begin
ACombo.Items.Clear;
for I:=0 to AStrings.Count-1 do
begin
ACombo.Items.Add(AStrings.Names[I]);
end;
ACombo.ItemIndex:=0;
end;
procedure Move(AFormClass: TIWAppFormClass);
begin
// 释放当前窗体
TIWAppForm(WebApplication.ActiveForm).Release;
// 创建下一个窗体
AFormClass.Create(WebApplication).Show;
end;
function GetDataDicList(DS:TDataSet;const KeyName, ValueName:String):TStrings;
begin
DS.Active:=True;
DS.First;
Result:=TStringList.Create;
while not DS.Eof do
begin
Result.Add(format('%s=%s', [ds.FieldByName(ValueName).AsString, ds.FieldByName(KeyName).AsString]));
DS.Next;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?