2016年1月

首页2016年1月
30
Jan
0

DELPHI XE8 远程调试

最近公司项目遇到问题需要远程调试
搜索了一下怎么用 发现网上能找到最新的是XE2上的说明
现在已经有一些不同了 按照上面的方法不能调试成功

经过测试XE8的方法如下:
1.项目编译设置:
微信截图_20160130101016.png
2.在被调试电脑上运行setup_paserver.exe文件可以从DELPHI电脑的目录
C:Program Files (x86)EmbarcaderoStudio16.0PAServersetup_paserver.exe下拷贝过去安装
3.安装完成后运行PSERVER就OK,密码可以为空.
微信截图_20160130101640.png
4.调试IDE的OPTION里设置远程调试服务器地址信息
微信截图_20160130100550.png
5.把DEBUG下编译的程序文件复制到调试机,这里有一个重要的文件调试符号缓存文件一定要带上(要不然无法断点)
微信截图_20160130100805.png
6.RUN LOADPRECESS
微信截图_20160130100620.png
7.congratulations

26
Jan
0

cxgrid导出excel

uses cxexportgrid4link;

var
SaveDialog: TSaveDialog;
begin
SaveDialog:=TSaveDialog.Create(nil);
with SaveDialog do
begin
Filter := '.xls|.xls';
if Execute then
begin
ExportGrid4ToExcel(FileName,vgrid,true,true,true,'xls');
end;
end;
SaveDialog.Free;
end;

5以上版本:

uses cxGridExportLink;

procedure ExpGridToXls(grid: TcxGrid);
var
SaveDialog: TSaveDialog;
begin
SaveDialog:=TSaveDialog.Create(nil);
with SaveDialog do
begin
Filter := 'xls|.xls|html|.htm|xml|*.xml|text|.txt';
if Execute then
begin
case SaveDialog.FilterIndex of
1: ExportGridToExcel(FileName, grid);
2: ExportGridToHTML(FileName, grid);
3: ExportGridToXML(FileName, grid);
4: ExportGridToText(FileName, grid);
end;
end;
end;
SaveDialog.Free;

end;

23
Jan
0

NativeXml用法

NativeXml可以在官网上下载,下载后将文件夹放在指定地方,打开DELPHI在其环境变量中引用NativeXml路径,然后在程序中引用NativeXml单元,我们就可以使用NativeXml了。

NativeXml的方法属性:

ANativeXml := TNativeXml.Create(Self);//创建

ANativeXml.XmlFormat := xfReadable; //格式

ANativeXml.EncodingString := 'UTF-8';//编码

ANativeXml.ExternalEncoding := seUTF8;

ANativeXml.LoadFromFile();//从文件夹中导入XML文件

ANativeXml.SaveToFile();//XML文件保存到文件夹

节点的方法属性:

ANativeXml.Root;//XML文件的根节点,注意一切都从根开始

ANativeXml.Root.NodeByName(‘节点名’);//通过节点名获得节点

NativeXml.Root.Attributes;//节点的属性对象

NativeXml.Root.ChildContainers;//节点的子节点对象

NativeXml.Root.NodeNew();//增加新的子节点

NativeXml.Root.Name;//节点名

NativeXml.Root.Value;//节点值

//===================================================
var
// XMLDoc:TXMLDocument;
// NodeRoot,NodeChild,NodeChilds:IXMLNode;
// NodeSubRoot :IXMLNodeList;
i,j:Integer;
xml: TNativeXml;
node:TXmlNode;
nodes :TsdNodeList;
nodeSub:TXmlNode;
begin
with acdsOnline do
begin

DisableControls;
Close;
CreateDataSet;
//添加数据
xml := TNativeXml.CreateEx(True,True,nil);
try
  xml.ReadFromString(aStr);
  nodes := xml.RootNodes;
  for i := 0 to nodes.Count - 1 do
  begin
    Append;
    node := nodes.Items[i];
    for j := 0 to node.NodeCount - 1 do
    begin
      nodeSub := node.Nodes[j];
      if nodeSub.Name = cXMLOnlineID then
        acdsOnline.FieldByName('F_PEERADDR').AsInteger := StrToInt(nodeSub.Value)
      else if nodeSub.Name = cXMLOnlineIP then
        acdsOnline.FieldByName('F_PEERADDR').AsString := nodeSub.Value
      else if nodeSub.Name = cXMLOnlineType then
        acdsOnline.FieldByName('F_CLIENTTYPE').AsString := nodeSub.Value
      else if nodeSub.Name = cXMLOnlineStartTime then
        acdsOnline.FieldByName('F_ConnectTime').AsString := nodeSub.Value
      else if nodeSub.Name = cXMLOnlinePort then
        acdsOnline.FieldByName('F_PEERPORT').AsInteger := StrToInt(nodeSub.Value)
      else if nodeSub.Name = cXMLOnlinePackage then
        acdsOnline.FieldByName('F_RCVDCNT').AsInteger := StrToInt(nodeSub.Value);
    end;
    Post;
  end;
finally
  FreeAndNil(xml);
end;
Open;
EnableControls;

end;

end;

var
xml: TNativeXml;
node:TXmlNode;
nodeSub:TXmlNode;
begin
xml := TNativeXml.CreateEx(True,True,nil);
try

xml.CreateName(cXMLWorkerGoodsPrintDataRoot,nil);
aClientDataSet.MergeChangeLog;
aClientDataSet.First;
while not aClientDataSet.Eof do
begin
  node := xml.Root.NodeNew(cXMLWorkerGoodsPrintDataRootSub);

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataDateTime);
  nodeSub.Value := aClientDataSet.FieldByName('F_ENTERDATETIME').AsString;

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataWorkerID);
  nodeSub.Value := aClientDataSet.FieldByName('F_SHOWWORKERID').AsString;

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataGoodsName);
  nodeSub.Value := aClientDataSet.FieldByName('F_GOODNAME').AsString;

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataClockType);
  nodeSub.Value := aClientDataSet.FieldByName('F_CLOCKTYPE').AsString;

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataAmount);
  nodeSub.Value := aClientDataSet.FieldByName('F_AMOUNT').AsString;

  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataDeduct);
  nodeSub.Value := aClientDataSet.FieldByName('F_DEDUCT').AsString;
  //16.2.85 xg 增加项目编号
  if aClientDataSet.FindField('F_CONSUMEID') <> nil  then
  begin
    nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataConsumeID);
    nodeSub.Value := aClientDataSet.FieldByName('F_CONSUMEID').AsString;
  end;
  //16.2.85 xg 增加房间编号
  if aClientDataSet.FindField('F_ROOMSHOWID') <> nil  then
  begin
    nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataRoomShowID);
    nodeSub.Value := aClientDataSet.FieldByName('F_ROOMSHOWID').AsString;
  end;
  //16.2.85 xg 增加房间编号
  if aClientDataSet.FindField('F_HANDBRANDSHOWID') <> nil  then
  begin
    nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataHandBrandID);
    nodeSub.Value := aClientDataSet.FieldByName('F_HANDBRANDSHOWID').AsString;
  end;
  //17.2.89 xg 是否手工传入打印
  nodeSub := node.NodeNew(cXMLWorkerGoodsPrintDataIsHand);
  if aIsHand then
    nodeSub.Value := '是'
  else
    nodeSub.Value := '';
  aClientDataSet.Next;
end;
Result := xml.WriteToLocalString;

finally

FreeAndNil(xml);

end;

simdesign-os-code-281-trunk.zip

22
Jan
0

TStringList类常用属性方法详解

//TStringList 常用方法与属性:
var
  List: TStringList;
  i: Integer;
begin
  List := TStringList.Create;
  List.Add('Strings1');           {添加}
  List.Add('Strings2');
  List.Exchange(0,1);             {置换}
  List.Insert(0,'Strings3');      {插入}
  i := List.IndexOf('Strings1');  {第一次出现的位置}
  List.Sort;                      {排序}
  List.Sorted := True;   {指定排序}
  List.Count;                     {总数}
  List.Text;                      {文本集合}
  List.Delete(0);                 {删除, 0是第一个数据}
  List.LoadFromFile('c:tmp.txt');{打开}
  List.SaveToFile('c:tmp.txt');  {保存}
  List.Clear;                     {清空}
  List.Free;                      {释放}
end;
 
//读入字符串
var
  List: TStringList;
begin
  List := TStringList.Create;
  List.CommaText := 'aaa,bbb,ccc,ddd';
  //相当于: List.Text := 'aaa' + #13#10 + 'bbb' + #13#10' + 'ccc' + '#13#10' + 'ddd';
 
  ShowMessage(IntToStr(List.Count));  //4
  ShowMessage(List[0]);  //aaa
 
  List.Free;
end;
 
//置换分隔符
var
  List: TStringList;
begin
  List := TStringList.Create;
  List.Delimiter := '|';
  List.DelimitedText := 'aaa|bbb|ccc|ddd';
 
  ShowMessage(IntToStr(List.Count));  //4
  ShowMessage(List[0]);  //aaa
 
  List.Free;
end;
//类似的哈希表操作法
var
  List: TStringList;
begin
  List := TStringList.Create;
 
  List.Add('aaa=111');
  List.Add('bbb=222');
  List.Add('ccc=333');
  List.Add('ddd=444');
 
  ShowMessage(List.Names[1]);  //bbb
  ShowMessage(List.ValueFromIndex[1]);  //222
  ShowMessage(List.Values['bbb']);  //222
 
  //ValueFromIndex 可以赋值:
  List.ValueFromIndex[1] := '2';
  ShowMessage(List[1]);  //bbb=2
 
  //可以通过 Values 赋值:
  List.Values['bbb'] := '22';
  ShowMessage(List[1]);  //bbb=22
 
  List.Free;
end;
 
//避免重复值
var
  List: TStringList;
begin
  List := TStringList.Create;
 
  List.Add('aaa');
 
  List.Sorted := True;  //需要先指定排序
  List.Duplicates := dupIgnore;  //如有重复值则放弃
 
  List.Add('aaa');
 
  ShowMessage(List.Text);  //aaa
 
  //Duplicates 有3个可选值:
  //dupIgnore: 放弃;
  //dupAccept: 结束;
  //dupError: 提示错误.
 
  List.Free;
end;
//排序与倒排序
{排序函数}
function DescCompareStrings(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result := -AnsiCompareText(List[Index1], List[Index2]);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  List: TStringList;
begin
  List := TStringList.Create;
 
  List.Add('bbb');
  List.Add('ccc');
  List.Add('aaa');
 
  //未排序
  ShowMessage(List.Text);  //bbb ccc aaa
 
  //排序
  List.Sort;
  ShowMessage(List.Text);  //aaa bbb ccc
 
  //倒排序
  List.CustomSort(DescCompareStrings);  //调用排序函数
  ShowMessage(List.Text);  //ccc bbb aaa
 
  //假如:
  List.Sorted := True;
  List.Add('999');
  List.Add('000');
  List.Add('zzz');
  ShowMessage(List.Text);  //000 999 aaa bbb ccc zzz
end;

22
Jan
0

DELPHI XE7新特性

1.Showmessage/msessagedlg/raise Exception 终于切换不卡死,虽然来晚了。以前做安卓用安卓的JNI解决对话框,现在可以用FMX对话框解决,但那个raise异常对话框还是无法替换。跨平台对话框终究才是出路。

2.ListView支持下拉刷新。ListView+各种风格,玩爆Listbox, 遐想无限。

3.加入了TMultiView和TDetailPanel ,,可以为做不同的分辨率。这个很重要。

4.FireMonkey Advertising support.The FireMonkey TBannerAd component now uses the Google Mobile Ads API from Google Play Services.

5.每个窗体都有 FireMonkey OnSaveState。SaveState而已保存和映射任意数据到本地,可以在不创建窗体下获取窗体数据。

procedure TForm1.FormCreate(Sender: TObject);
var
R: TBinaryReader;
begin
if SaveState.Stream.Size > 0 then
begin

// Recover previously typed text in Edit1 control.
R := TBinaryReader.Create(SaveState.Stream);
try
  Edit1.Text := R.ReadString;
finally
  R.Free;
end;

end;
end;

procedure TForm1.FormSaveState(Sender: TObject);
var
W: TBinaryWriter;
begin
SaveState.Stream.Clear;
// Save typed text in Edit1 control.
W := TBinaryWriter.Create(SaveState.Stream);
try

W.Write(Edit1.Text);

finally

W.Free;

end;
end;

6.增强改善:FireMonkey TWebBrowser。
· EnableCaching – when set to False, if the file is updated and you try to reload it, the page will be updated.
· Stop – to cancel the loading of a web page.
· CaptureBitmap – will capture the currently visible web page as a bitmap. The purpose of this feature is to allow you to hide the WebBrowser control, display the bitmap and overlay other components (such as buttons or popups) on top of the bitmap.

7.FireDAC 的一些增强功能。FDAC终究替代DBX/UNIDAC(除了直连)/CDS。

· New IBLite Driver for desktop and mobile deployment
· Support for Blob real streaming, without buffering on client side. This includes the ability
for an application to get an internal stream reference. For example:

FDQuery.SQL.Text := 'select :p = BLOBField from tab where id = :id';

FDQuery.Params[0].DataType := ftStream;

FDQuery.Params[0].StreamMode := smOpenRead;

FDQuery.Params[1].AsInteger := 123;

FDQuery.OpenOrExecute;

// TFDParam.AsStream returns reference to internal low-level stream

FDQuery.Params[0].AsStream.Read(Buffer, Length(Buffer));
· Support for MSSQL file streams.
· TFDSchemaAdapter has been extended to support advanced serialization and delta processing:
o To serialize several datasets related to each other on the server side.
o To send the delta for these datasets from client to server.
o To load and store the delta on the server side inside of the datasets without opening / executing the queries.
o To apply the delta on the server side in the chronological order of the changes.
· Support for DBMS API command native timeouts.
· FireDAC connection parameters are now displayed in the Object Inspector as a record.

8.Delphi RTL Enhancements。核心RTL一些增强,个人觉得面向移动/互联网的单元功能整合更强了,当然也是基于跨平台。

Added System.NetEncoding unit in RTL. This unit provides a new TNetEncoding class to unify all internet encoding/decoding:

TNetEncoding.Base64.EncodeString(S);
TNetEncoding.Base64.DecodeString(S);
TNetEncoding.URL.EncodeString(S);
TNetEncoding.URL.DecodeString(S);
TNetEncoding.HTML.EncodeString(S);
TNetEncoding.HTML.DecodeString(S);

o This replaces EncodeString, DecodeString, EncodeBase64, DecodeBase64, HTTPEncode, HTTPDecode, HTMLEncode, HTMLDecode...and the AnsiString versions which are now deprecated.
· Updated Zlib library version to 1.2.8.
· OmniXML is included as a new provider for the XML framework.

9.FireMonkey Support for Immersive Full-Screen Mode of KitKat。

10.动态数组新语法,可以不用Setlength,赋值时候有点类似动态语言。这是我最喜欢的语法。每次新语法都是为了提高生产率。另外,,再劝那些用户则XE系列写着D7的同学,学点新东西,学点新语法吧,否则还是面对陌生的IDE。

String-like operations on Dynamic Arrays
o B := [1, 2, 3, 4];
o B := B + [5, 6, 7];
o Insert([6, 7, 8], B, 5); // inserts array [6, 7, 8], into B at index 5
o Delete(B, 1, 3); // deletes 3 elements starting at index 1
o Concat([1,2,3,4],[5,6,7])
o var B: TBytes = [1, 2, 3, 4];
· Improved initialization for Dynamic Arrays
o B := [1, 2, 3, 4];
o B := B + [5, 6, 7];

type
TBytes = array of Byte;
TBytesArray = array of TBytes;
TStrDA = array of string;

resourcestring
Sabc = 'abc';
Sdef = 'def';

var
B: TBytes = [1, 2, 3, 4];
C: TBytesArray = [[1, 2, 3], [4,5,6]];
D: TStrDA = ['ABC', 'DEF'];
E: TStrDA = [ Sabc, Sdef ];

12.FMX一些重构和优化。不再列举。
13.根据内幕,,beta2已经出来,xe7 理论上支持所有的ios 原生控件

14.还有其他,,关键还是beta1。