-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
delphi utils
- Loading branch information
0 parents
commit b11b2a8
Showing
6 changed files
with
1,353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
unit ExportData; | ||
|
||
interface | ||
|
||
uses Oracle, OracleData, Classes, ComObj; | ||
|
||
type TExport = class | ||
private | ||
fFullPath: string; | ||
fDataSet: TOracleDataSet; | ||
|
||
function CorrectData: Boolean; | ||
public | ||
constructor Create(aFullPath: String; aOraSataSet: TOracleDataSet); overload; | ||
|
||
property FullPath: string read fFullPath write fFullPath; | ||
property OraDataSet: TOracleDataSet read fDataSet write fDataSet; | ||
|
||
function ExportOraToCSV: Boolean; | ||
function ExportOraToXLS(aShowTitle: Boolean): Boolean; | ||
//function ExportOraToXLSX: Boolean; | ||
end; | ||
|
||
implementation | ||
|
||
constructor TExport.Create(aFullPath: String; aOraSataSet: TOracleDataSet); | ||
begin | ||
fFullPath := aFullPath; | ||
fDataSet := aOraSataSet; | ||
end; | ||
|
||
function TExport.CorrectData: Boolean; | ||
begin | ||
// | ||
end; | ||
|
||
function TExport.ExportOraToCSV: Boolean; | ||
var | ||
f: TextFile; | ||
i: Integer; | ||
begin | ||
try | ||
AssignFile(f, fFullPath); | ||
//Rewrite(f); | ||
Reset(f); | ||
fDataSet.First; | ||
while not fDataSet.Eof do | ||
begin | ||
for i := 0 to fDataSet.FieldCount - 1 do | ||
begin | ||
Writeln(f, fDataSet.Fields.FieldByNumber(i).Value + ';'); | ||
end; | ||
fDataSet.Next; | ||
end; | ||
finally | ||
CloseFile(f); | ||
end; | ||
|
||
end; | ||
|
||
function TExport.ExportOraToXLS(aShowTitle: Boolean): Boolean; | ||
var | ||
x: Variant; | ||
i, j: Integer; | ||
begin | ||
x := CreateOleObject('Excel.Application'); | ||
x.Workbooks.Add; | ||
|
||
j := 1; | ||
if aShowTitle then | ||
begin | ||
for i := 0 to fDataSet.FieldCount - 1 do | ||
x.ActiveWorkBook.WorkSheets[1].Cells[j, i + 1] := | ||
fDataSet.Fields.Fields[i].DisplayLabel; | ||
j := 2; | ||
end; | ||
|
||
while not fDataSet.Eof do | ||
begin | ||
for i := 0 to fDataSet.FieldCount - 1 do | ||
begin | ||
x.ActiveWorkBook.WorkSheets[1].Cells[j, i + 1] := | ||
fDataSet.Fields.Fields[i].AsString; | ||
end; | ||
fDataSet.Next; | ||
inc(j); | ||
end; | ||
x.Visible := true; | ||
end; | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
unit MarshalOblect; | ||
|
||
interface | ||
|
||
uses | ||
SysUtils, DBXJSON, DBXJSONReflect; | ||
|
||
function DeepCopy(aValue: TObject): TObject; | ||
function ObjectTOJson(aObject: TObject): String; //TJSONValue; | ||
function JsonTOObject(aJson: TJSONValue): TObject; | ||
|
||
implementation | ||
|
||
function DeepCopy(aValue: TObject): TObject; | ||
var | ||
MarshalObj: TJSONMarshal; | ||
UnMarshalObj: TJSONUnMarshal; | ||
JSONValue: TJSONValue; | ||
begin | ||
Result:= nil; | ||
MarshalObj := TJSONMarshal.Create; | ||
UnMarshalObj := TJSONUnMarshal.Create; | ||
try | ||
JSONValue := MarshalObj.Marshal(aValue); | ||
try | ||
if Assigned(JSONValue) then | ||
Result:= UnMarshalObj.Unmarshal(JSONValue); | ||
finally | ||
JSONValue.Free; | ||
end; | ||
finally | ||
MarshalObj.Free; | ||
UnMarshalObj.Free; | ||
end; | ||
end; | ||
|
||
function ObjectTOJson(aObject: TObject): String; //TJSONValue; | ||
var | ||
MarshalObj: TJSONMarshal; | ||
begin | ||
Assert(Assigned(aObject), '{9682C06D-717C-4E75-9F81-38D2B64DCB96}'); | ||
|
||
MarshalObj := TJSONMarshal.Create; | ||
try | ||
Result := MarshalObj.Marshal(aObject).ToString; | ||
finally | ||
FreeAndNil(MarshalObj); | ||
end; | ||
end; | ||
|
||
function JsonTOObject(aJson: TJSONValue): TObject; | ||
var | ||
UnMarshalObj: TJSONUnMarshal; | ||
begin | ||
Assert(Assigned(aJson), '{A3A45FE9-7E30-4662-A279-00A917FD099F}'); | ||
|
||
UnMarshalObj := TJSONUnMarshal.Create; | ||
try | ||
Result:= UnMarshalObj.Unmarshal(aJson); | ||
finally | ||
FreeAndNil(UnMarshalObj); | ||
end; | ||
end; | ||
|
||
end. |
Oops, something went wrong.