delphi tips and articles 5
6776 단어 Delphi
procedure TForm1.Button1Click(Sender: TObject);
var
t:string;
s,s1:WideString;
v:WideChar;
begin
s := '_3~8년
s1:=년;
v:=s[1];
showmessage(v);
if ansiContainsText(s,s1[1]) then
begin
s:= AnsiReplaceText(s,s1[1],'');
s1:='끝';
s := ansireplaceText(s,s1[1],'');
s := ansireplaceText(s,'_','');
showmessage(s);
end;
showmessage(inttostr( Ord(v)));
end;
WideString의 경우 s[1]은 첫 번째 문자를 의미합니다.
2String - WideString
http://groups.google.com/group/borland.public.delphi.winapi/browse_frm/thread/7920cdc4c4d4f1ab/2bed31bcb703d614?lnk=st&q=delphi+string+to+widestring&rnum=1#2bed31bcb703d614
I just wasted 4 hours so maybe I can save some of your time.
Assigning a
string to a
widestring such as in:
var wString: wideString; nString: string; begin nString := 'hello'; wString := nString; end; works fine UNLESS the nString is greater than 4096 characters, in
which case the assignment to wString results in a empty
string.
3 창 최소화와 같은 유사 이벤트 캡처
Form에 TApplication Events를 놓고 OnMinimize 이벤트에서 최소화 메시지를 포착합니다.
TApplicationEvents, additional 패널
4가지 일반적인 Grid를 excel로 내보내기
a cxgrid:
uses
cxExportGrid4Link;
procedure TForm1.Button1Click(Sender: TObject); begin ExportGrid4ToEXCEL('d:/wang.xsl',cxGrid1,True,True); ExportGrid4ToTEXT('d:/wang.txt',cxGrid1,True,True); ExportGrid4ToXML('d:/wang.xml',cxGrid1,True,True); ExportGrid4ToHTML('d:/wang.html',cxGrid1,True,True); end; bdbgrid와stringgrid
procedure TDM.CopyDbDataToExcel(Target: TDBGridEh;mb,FileName: string);variCount, jCount: Integer;XLApp: Variant;Sheet: Variant;beginScreen.Cursor := crHourGlass;if not VarIsEmpty(XLApp) thenbeginXLApp.DisplayAlerts := False;XLApp.Quit;VarClear(XLApp);end;//--------------------------템플릿 선택 - - -//CopyFile(pChar(ExtractFilePath(Application.exeName) + mb+'입니다.xls'),pChar(FileName+'1.xls'),false);//------------------------//ole를 통해 Excel 대상tryXLApp를 만듭니다: = CreateOleObject ('Excel.Application ')exceptScreen.Cursor := crDefault;Exit;end;if mb ='통계 - 프로젝트 정보 전'then XLApp.WorkBooks.Add[Trim(ExtractFilePath(Application.exeName))+mb+'.xls']//데이터를 거기에 놓으세요. e:/1에 파일을 만드세요.xlselseXLApp.WorkBooks.Add;XLApp.WorkBooks[1].WorkSheets[1].Name := 'sheet1';Sheet := XLApp.Workbooks[1].WorkSheets['sheet1'];if not Target.DataSource.DataSet.Active thenbeginScreen.Cursor := crDefault;Exit;end;Target.DataSource.DataSet.first;
for iCount := 0 to Target.Columns.Count - 1 dobeginSheet.cells[1, iCount + 1] := trim(Target.Columns.Items[iCount].Title.Caption);end;
jCount := 1;while not Target.DataSource.DataSet.Eof dobegin
for iCount := 0 to Target.Columns.Count - 1 do//begin if iCount = 0 then Sheet.cells[jCount + 1, iCount + 1] := IntToStr(jCount) else Sheet.cells[jCount + 1, iCount + 1] := trim(Target.Columns.Items[iCount].Field.AsString);end;Inc(jCount);Target.DataSource.DataSet.Next;end;
//----------------- Excel의 매크로를 추가할 수 있음 - - - - - - - -
XLApp.ActiveWorkbook.SaveAs(FileName:=FileName); ;Screen.Cursor := crDefault;XLApp.ActiveWorkbook.Close;end;-----------------------------------------StringGridToExcel
procedure TDM.CopySGDataToExcel(Target: TStringGrid;FileName: string);variCount, jCount: Integer;XLApp: Variant;Sheet: Variant;beginScreen.Cursor := crHourGlass;if not VarIsEmpty(XLApp) thenbeginXLApp.DisplayAlerts := False;XLApp.Quit;VarClear(XLApp);end;//ole를 통해 Excel 대상tryXLApp를 만듭니다: = CreateOleObject ('Excel.Application ')exceptScreen.Cursor := crDefault;Exit;end;XLApp.WorkBooks.Add;//당신은 데이터를 거기에 두어야 합니다. 선생은 e:/1에 파일을 만들어야 합니다.xlsXLApp.WorkBooks[1].WorkSheets[1].Name := 'sheet1';Sheet := XLApp.Workbooks[1].WorkSheets['sheet1'];Target.Row := 0;for iCount := 0 to Target.RowCount - 1 dobeginfor jCount := 0 to Target.ColCount - 1 do Sheet.cells[iCount + 1, jCount + 1] := Target.Cells[jCount,iCount];Target.Row := iCount;end;XLApp.ActiveWorkbook.SaveAs(FileName:=FileName);Screen.Cursor := crDefault;XLApp.ActiveWorkbook.Close;end;
dbgridtoexcel 참조 2:
procedureCopyDbDataToExcel(Target:TDbgrid);var iCount,jCount:Integer; XLApp:Variant; Sheet:Variant;begin Screen.Cursor:=crHourGlass;ifnotVarIsEmpty(XLApp)thenbegin XLApp.DisplayAlerts:=False; XLApp.Quit; VarClear(XLApp);end;//ole를 통해 Excel 대상try XLApp:=CreateOleObject('Excel.Application') 만들기;except Screen.Cursor:=crDefault; Exit;end; XLApp.WorkBooks.Add; XLApp.WorkBooks[1].WorkSheets[1].Name:='테스트 워크북';Sheet:=XLApp.Workbooks[1].WorkSheets['테스트 워크북'];ifnotTarget.DataSource.DataSet.Activethenbegin Screen.Cursor:=crDefault; Exit;end; Target.DataSource.DataSet.first;foriCount:=0toTarget.Columns.Count-1dobegin Sheet.cells[1,iCount+1]:=Target.Columns.Items[iCount].Title.Caption;end; jCount:=1;whilenotTarget.DataSource.DataSet.EofdobeginforiCount:=0toTarget.Columns.Count-1dobegin Sheet.cells[jCount+1,iCount+1]:=Target.Columns.Items[iCount].Field.AsString;end; Inc(jCount); Target.DataSource.DataSet.Next;end; XlApp.Visible:=True; Screen.Cursor:=crDefault;end;
5 TstringList에서 Object 사용
http://forums.devshed.com/delphi-programming-90/namevaluecollection-equivalent-in-delphi-6-0t-299165.html
1.Note that TStringList has an AddObject method, as well as an Add method. You can use AddObject to associate an object with a string. 2. The trick with AddObject is that the second object must be a descendant of TObject. This is no problem, since we can declare our value type as a TObject descendant:
Code:
type:
TMyValue = class(TObject)
public
nValue : integer;
end;
This is assuming that the data we want to store (nValue) is an integer. It can be a more complex type if you like (say, a bunch of values).
3. Then to add an item to the StringList, do something like this:
Code:
procedure TForm1.AddNameValue(sName: string; nValue: integer);
var
oMyValue : TMyValue;
begin
oMyValue := TMyValue.Create;
oMyValue.nValue := nValue;
stl.AddObject(sName, oMyValue);
end;
4. Now to get a value off the StringList, you can get the object associated with the string and cast it back to a TMyValue and extract the values from the object. It might be faster if you set StringList.sorted := true, so that the stringlist is sorted to start with.
5. To clear the list, you go through each entry in the stringlist, get the object (via the StringList.Objects[i] method) and free each one first. Then clear the stringlist.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Delphi] TStringBuilder그리고 꼭 사용해야만 할까? 그림처럼 Heap 영역에 "Hello" 공간을 생성하고 포인팅을 한다. "Hello World" 공간을 새로 생성한 후 포인팅을 하게 된다. 결국 "Hello" 라는 String 객체가 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.