ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: id09318 ที่ 07 กรกฎาคม 2016, 16:42:59



หัวข้อ: ขอคำแนะนำหน่อยครับ เค้าให้ code เรามา เราจะคอมไพล์ ออกมาอีกทีทำไงครับ
เริ่มหัวข้อโดย: id09318 ที่ 07 กรกฎาคม 2016, 16:42:59
เราสามารถใช้ พวก vs vb สร้างมันออกมาได้่ไหมครับ
แล้วเราจะสร้างมันได้ยังไงครับ

โค๊ด:
procedure TForm1.btnDat2XmlClick(Sender: TObject);
var
  XMLDoc: TXMLDocument;
  Node1: IXMLNode;
  Node2: IXMLNode;
  MyStream: TMemoryStream;
  i: integer;
begin
  if FileExists('.\GoodsSale_Tw.dat') then begin
    XMLDoc := TXMLDocument.Create(nil);
    XMLDoc.Active := True;
    XMLDoc.Version := '1.0';
    XMLDoc.Encoding := 'GB2312';
    XMLDoc.Options := [doNodeAutoCreate, doNodeAutoIndent, doAttrNull, doAutoPrefix, doNamespaceDecl];
    XMLDoc.DocumentElement := XMLDoc.CreateNode('table');
    myStream := TMemoryStream.Create;
    myStream.LoadFromFile('.\GoodsSale_Tw.dat');
    Count := (myStream.Size - 40) div 10;
    //myStream.ReadBuffer(Head[0], 10);
    MyStream.Position := 10;
    for i := 0 to Count - 1 do
    begin
      new(Pgshop);
      MyStream.Read(Pgshop^, sizeof(gshop_info));
      Node1 := XMLDoc.DocumentElement;
      Node2 := Node1.AddChild('row');
      if ((i + 1) mod 2) <> 0 then begin
        Node2.SetAttributeNS('大类', '', Pgshop^.a1 xor $72);
        Node2.SetAttributeNS('位置', '', Pgshop^.a2 xor $67);
        Node2.SetAttributeNS('物品ID', '', Pgshop^.a3 xor $AA13);
        Node2.SetAttributeNS('折叠数量', '', Pgshop^.a5 xor $86);
        Node2.SetAttributeNS('价格', '', Pgshop^.a6 xor $DFB0);
        Node2.SetAttributeNS('功能1', '', Pgshop^.a8 xor $C2);
        Node2.SetAttributeNS('功能2', '', Pgshop^.a9 xor $C8);
        Node2.SetAttributeNS('标识', '', Pgshop^.a10 xor $9D);
      end else begin
        Node2.SetAttributeNS('大类', '', Pgshop^.a1 xor $4E);
        Node2.SetAttributeNS('位置', '', Pgshop^.a2 xor $B0);
        Node2.SetAttributeNS('物品ID', '', Pgshop^.a3 xor $D103);
        Node2.SetAttributeNS('折叠数量', '', Pgshop^.a5 xor $BC);
        Node2.SetAttributeNS('价格', '', Pgshop^.a6 xor $8E05);
        Node2.SetAttributeNS('功能1', '', Pgshop^.a8 xor $07);
        Node2.SetAttributeNS('功能2', '', Pgshop^.a9 xor $92);
        Node2.SetAttributeNS('标识', '', Pgshop^.a10 xor $80);
      end;
    end;
    //myStream.ReadBuffer(LastRecord, 10);
    //myStream.ReadBuffer(Bottom[0], 20);
    XMLDoc.SaveToFile('.\GoodsSale_Tw.xml');
    XMLDoc.Free;
    myStream.Free;
  end;
end;

procedure TForm1.btnXml2DatClick(Sender: TObject);
var
  XMLDoc: TXMLDocument;
  Node, Node1: IXMLNode;
  MyStream: TMemoryStream;
  i, Count: integer;
begin
  if FileExists('.\GoodsSale_Tw.xml') then begin
    XMLDoc := TXMLDocument.Create(Application);
    XMLDoc.LoadFromFile('.\GoodsSale_Tw.xml');
    XMLDoc.Active := True;
    Node := XMLDoc.DocumentElement;
    Count := Node.ChildNodes.Count;
    myStream := TMemoryStream.Create;
    myStream.Write(Head[0], Length(Head));
    for i := 0 to Count - 1 do begin
      Node1 := XMLDoc.DocumentElement.ChildNodes[i];
      new(Pgshop);
      if ((i + 1) mod 2) <> 0 then begin
        Pgshop^.a1 := Byte(StrToInt(Node1.Attributes['大类'])) xor $72;
        Pgshop^.a2 := Byte(StrToInt(Node1.Attributes['位置'])) xor $67;
        Pgshop^.a3 := StrToInt(Node1.Attributes['物品ID']) xor $AA13;
        Pgshop^.a5 := Byte(StrToInt(Node1.Attributes['折叠数量'])) xor $86;
        Pgshop^.a6 := StrToInt(Node1.Attributes['价格']) xor $DFB0;
        Pgshop^.a8 := Byte(StrToInt(Node1.Attributes['功能1'])) xor $C2;
        Pgshop^.a9 := Byte(StrToInt(Node1.Attributes['功能2'])) xor $C8;
        Pgshop^.a10 := Byte(StrToInt(Node1.Attributes['标识'])) xor $9D;
      end else begin
        Pgshop^.a1 := Byte(StrToInt(Node1.Attributes['大类'])) xor $4E;
        Pgshop^.a2 := Byte(StrToInt(Node1.Attributes['位置'])) xor $B0;
        Pgshop^.a3 := StrToInt(Node1.Attributes['物品ID']) xor $D103;
        Pgshop^.a5 := Byte(StrToInt(Node1.Attributes['折叠数量'])) xor $BC;
        Pgshop^.a6 := StrToInt(Node1.Attributes['价格']) xor $8E05;
        Pgshop^.a8 := Byte(StrToInt(Node1.Attributes['功能1'])) xor $07;
        Pgshop^.a9 := Byte(StrToInt(Node1.Attributes['功能2'])) xor $92;
        Pgshop^.a10 := Byte(StrToInt(Node1.Attributes['标识'])) xor $80;
      end;
      myStream.Write(Pgshop^, SizeOf(gshop_info));
    end;
    myStream.Write(LastRecord[0], Length(LastRecord));
    myStream.Write(Bottom[0], Length(Bottom));
    myStream.SaveToFile('.\GoodsSale_Tw1.dat');
    myStream.Free;
  end;
end;


หัวข้อ: Re: ขอคำแนะนำหน่อยครับ เค้าให้ code เรามา เราจะคอมไพล์ ออกมาอีกทีทำไงครับ
เริ่มหัวข้อโดย: rapiz ที่ 07 กรกฎาคม 2016, 17:58:24
ภาษา Delphi (เดลไฟ) ครับ แต่ไม่แน่ใจว่า V อะไร  :wanwan006: เขียนง่ายครับ ภาษานี้ ผมฝึกตอนเริ่มเขียนโค๊ดเลย


ฝากลายเซ็นด้วยนะครับ


หัวข้อ: Re: ขอคำแนะนำหน่อยครับ เค้าให้ code เรามา เราจะคอมไพล์ ออกมาอีกทีทำไงครับ
เริ่มหัวข้อโดย: mango ที่ 08 กรกฎาคม 2016, 03:37:23
เข้ามาเก็บความรู้ต่อเนื่อง  :wanwan011:


หัวข้อ: Re: ขอคำแนะนำหน่อยครับ เค้าให้ code เรามา เราจะคอมไพล์ ออกมาอีกทีทำไงครับ
เริ่มหัวข้อโดย: sputtaro ที่ 08 กรกฎาคม 2016, 15:26:01
เป็นโค๊ดภาษาเดลไฟครับ
ต้องใช้โปรแกรมเดลไฟ เปิดถึงจะคอมไพล์ได้
น่าจะใช้ได้กับทุกเวอร์ชั่นที่ใช้ TXMLDocument ได้นะครับ เพราะไม่มีอะไรเป็นพิเศษ

กรณีที่คุณต้องการสร้างด้วย VB (รวมไปถึงภาษาอื่นๆที่อ่านไฟล์ .dat ได้)
ก็น่าจะทำได้ไม่ยาก เพราะ
โค๊ดที่ให้มา เป็นการสร้างฟอร์มขึ้นมา 1 ฟอร์ม มี 2 ปุ่ม

ปุ่มแรก -- btnDat2XmlClick
ให้อ่านไฟล์ GoodsSale_Tw.dat
จากโค๊ด -- if FileExists('.\GoodsSale_Tw.dat')
แล้วเก็บลงในหน่วยความจำ -- TMemoryStream
ต่อจากนั้น เซฟเป็นไฟล์ .xml
จากโค๊ด -- .SaveToFile('.\GoodsSale_Tw.xml');

ปุ่มที่ 2 -- btnXml2DatClick
ก็หลักการเดียวกัน แต่อ่านและเซฟ สลับกันคือ
ให้อ่านไฟล์ GoodsSale_Tw.xml
จากโค๊ด -- if FileExists('.\GoodsSale_Tw.xml')
แล้วเก็บลงในหน่วยความจำ -- TMemoryStream
ต่อจากนั้น เซฟเป็นไฟล์ .dat
จากโค๊ด -- SaveToFile('.\GoodsSale_Tw1.dat');

หากคุณพอมีพื้นฐานบ้าง ผมคิดว่าไม่ยากเลยครับ

*******************************
หวังว่าจะมีประโยชน์บ้างนะครับ