1、通过MainForm修改UniHTMLFrame中的元素值:
self.UniHTMLFrame1.JSInterface.JSCode('document.getElementById("xlf").innerText="新的值";');
2、删除记录确认,同时修改提示框的标题栏
if UniMainModule.UserList.RecNo>=1 then
MessageDlg('确定要删除当前记录吗?',mtConfirmation,mbYesNo,
procedure(Sender:TComponent;res:integer)
begin
if res=mrYes then
UniMainModule.UserList.Delete;
end
);
UniSession.AddJS('Ext.get("messagebox-1001_header-title-textEl").setText("警告")');
3、创建新的卡片,并载入页面
procedure TMainForm.UniButton1Click(Sender: TObject);
var
sheet:Tunitabsheet;
begin
sheet:=Tunitabsheet.Create(unipagecontrol1);
sheet.Caption:='新的选项卡';
sheet.PageControl:=unipagecontrol1;
sheet.Visible:=true;
sheet.Closable:=true;
sheet.SetFocus;
Tuniframe1.Create(self).Parent:=sheet;
self.UniPageControl1.ActivePage:=sheet;
end;
4、自定义右键菜单
procedure TMainForm.UniDBGrid1CellContextClick(Column: TUniDBGridColumn; X,
Y: Integer);
begin
UniPopupMenu1.Popup(X, Y, self.UniDBGrid1);
end;
需要在MainModule中将BrowserOptions中的boDisableMouseRightClick设置为True
5、UniDBGrid的标题栏排序
procedure TMainForm.UniDBGrid1ColumnSort(Column: TUniDBGridColumn;
Direction: Boolean);
begin
if Direction then UniMainModule.UserList.Sort := Column.FieldName + ' ASC'
else UniMainModule.UserList.Sort := Column.FieldName + ' DESC' ;
end;
同时将UniDBGrid的所有列的Sortable设置为true,Menu中的ColumnHideable设置为false
6、获取showmodal窗口的返回值并继续以下的操作
procedure TMainForm.CalB2(Sender:TComponent;AResult:Integer);
begin
if AResult=mrYes then
begin
UniMainModule.UserList.Post;
ShowMessage('会员信息修改并保存成功!');
end
else
begin
UniMainModule.UserList.Cancel;
end;
end;
procedure TMainForm.UniDBGrid1DblClick(Sender: TObject);
begin
if unimainmodule.UserList.RecNo>=1 then
begin
uniform2.LoadComboboxList(uniform2.UniDBCombobox2,'省份');
uniform2.LoadComboboxList(uniform2.UniDBCombobox4,'民族');
uniform2.LoadComboboxList(uniform2.UniDBCombobox5,'文化程度');
uniform2.InitData;
UniMainModule.UserList.Edit;
uniform2.showmodal(CalB2);//这里要用CallBack形式调用showmodal
end;
end;
7、上传文件自动改名
procedure TMainForm.UniFileUploadButton1Completed(Sender: TObject;
AStream: TFileStream);
var
oldfilename,newfilename,filepath:string;
begin
filepath:=Extractfilepath(AStream.FileName);
if rightstr(filepath,1)<>'\' then
filepath:=filepath+'\';
oldfilename:=AStream.FileName;
newfilename:=filepath+formatdatetime('PyyyymmddHHMMSSZZZ',now())+extractfileext(oldfilename);
freeandnil(AStream);//释放原来的文件流,以免改名失败
try
renamefile(oldfilename,newfilename);
finally
UniImage1.Picture.LoadFromFile(newfilename);
self.UniEdit2.Text:=extractfilename(newfilename);
end;
end;
8、通过UniHTMLFrame中的菜单跳转打开新的窗口
在UniHTMLFrame中的HTML代码中:
<a href="javascript:ajaxRequest(MainForm.window,'jumpurl',['cmd=发布']);">发布</a>
在MainForm的OnAjaxEvent中:
procedure TMainForm.UniFormAjaxEvent(Sender: TComponent; EventName: string;
Params: TUniStrings);
var
s:string;
freeform:TUniForm1;
begin
if EventName = 'jumpurl' then
begin
freeform:=TUniForm1.Create(UniApplication);
freeform.Caption:=Params.Params['cmd'].AsString;
freeform.ShowModal;
end;
end;
9、动态切换外观皮肤
在MainForm的UniFormshow中:
procedure TMainForm.UniFormShow(Sender: TObject);
var
S : TUniStringArray;
I : Integer;
begin
S := UniServerModule.ThemeManager.AllThemes;
ThemeComboBox.Items.Clear;
for I := Low(S) to High(S) do
ThemeComboBox.Items.Add(S[I]);
self.ThemeComboBox.Text:=UniMainModule.Theme;
end;
同时将ThemecomboBox中:
UniMainModule.Theme:=self.ThemeComboBox.Text;
将MainModule的RecallLastTheme属性设置True
10、修改UniDBGrid的行高,同时将选中的单元格边框清除
在ServerModule的CustomCSS中放如下样式:
.x-grid-row{
line-height:32px;
}
.x-grid-item-focused .x-grid-cell-inner:before {
border: none !important;
}
11、在UniGUI中利用FastReport实现数据打印
在主窗口中用按钮或右键菜单,打开预览窗口:Uniform3.ShowModal;
在UniForm3中放置:UniURLFrame1(对齐方式:alClient)、frxReport1、frxDBDataSet1、frxPDFExport1。
在UniFormBeforeShow中写入:
UniMainModule.PRUser.Close;
UniMainModule.PRUser.SQL.Text:=UniMainModule.UserList.SQL.Text;
UniMainModule.PRUser.Open;
try
PrepareAndShow(frxReport1, frxPDFExport1);
finally
UniMainModule.PRUser.Close;
end;
创建打印的过程:
procedure TUniForm3.PrepareAndShow(Report: TfrxReport; Exp: TfrxPDFExport);
var
pa,AUrl : string;
begin
Report.PrintOptions.ShowDialog := False;
Report.ShowProgress := false;
Report.EngineOptions.SilentMode := True;
Report.EngineOptions.EnableThreadSafe := True;
Report.EngineOptions.DestroyForms := False;
Report.EngineOptions.UseGlobalDataSetList := False;
pa:=UniServerModule.FilesFolderPath+'PrtStudent.fr3';
Report.LoadFromFile(pa);
Exp.Background := True;
Exp.ShowProgress := False;
Exp.ShowDialog := False;
Exp.FileName := UniServerModule.NewCacheFileUrl(False, 'pdf', '', '', AUrl, True);
Exp.DefaultPath := '';
Report.PreviewOptions.AllowEdit := False;
Report.PrepareReport;
Report.Export(Exp);
UniURLFrame1.URL := AUrl;
end;
12、关于UniDateTimePicker的使用
默认情况下UniDateTimePicker里显示的是当前的日期,如果想让日期为空,可以在UniForm的show中写入UniDateTimePicker1.DateTime:=0
判断日期是否为空:
if (self.UniDateTimePicker1.DateTime<>0) then //如果日期不为空