社区
C++ Builder
帖子详情
新建 CPP File与Unit
lovetsfuer
2014-02-17 04:41:25
这2个新建使用上的区别?麻烦给介绍下
...全文
76
5
打赏
收藏
新建 CPP File与Unit
这2个新建使用上的区别?麻烦给介绍下
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
小乖乖_学技术
2014-02-17
打赏
举报
回复
sololie
2014-02-17
打赏
举报
回复
没啥大的区别,unit预置了一些代码,实际就是个代码模板 //unit1.h #ifndef Unit1H #define Unit1H //...... #endif //unit1.cpp #pragma hdrstop #include "Unit1.h" //...... #pragma package(smart_init) #pragma hdrstop 表示预编译头文件到此为止,后面的头文件不进行预编译。CB可以预编译头文件以加快链接的速度,但如果所有头文件都进行预编译又可能占太多磁盘空间,所以使用这个选项排除一些头文件。 有时单元之间有依赖关系,比如单元A依赖单元B,所以单元B要先于单元A编译。你可以用#pragma startup指定编译优先级,如果使用了#pragma package(smart_init) ,CB就会根据优先级的大小先后编译。 如果你要新建一个类,而又想省去一些代码就用unit。 啥都想自己写,或者不需要头文件就直接新建个cpp 不管怎么都取决于你自己,想怎样就怎样
ccrun.com
2014-02-17
打赏
举报
回复
建议新建一个Unit,然后将类的声明写在.h文件中,将类的实现写在.cpp文件中。
lovetsfuer
2014-02-17
打赏
举报
回复
引用 1 楼 sololie 的回复:
unit 包含一个.cpp 和.h cpp就只是一个.cpp
好吧,我没说清楚,带.h与不带使用上区别? C#中,写个公用的类,就新建个类,BCB上新建unit?还是cpp
sololie
2014-02-17
打赏
举报
回复
unit 包含一个.cpp 和.h cpp就只是一个.cpp
DELPHI TXT 树文档 管理器
unit
TreeViewFunctions; interface uses Windows, Messages, SysUtils, Variants, Classes, ComCtrls, Controls, Forms,
File
Ctrl, StrUtils, Masks, Vcl.OleCtrls, SHDocVw, IOUtils; procedure SaveTreeViewExplandState(TreeView: TTreeView;
File
Name: string); procedure LoadTreeViewExplandState(TreeView: TTreeView;
File
Name: string); function ExtractNewFolderPath(
File
Name: string; NewText: string): string; procedure HideHideHorizontalScrollBar(TreeView: TTreeView); function IsEmptyDir(sDir: String): Boolean; function AttachMentsExists(
File
Name: String): Boolean; procedure SetIcons(TreeView: TTreeView; list: TStringList); procedure EnumText(s: string; aItem: TTreeNode); function AttachmentsFolder(
File
Name: String): string; function ExtractNodeFullPath(TreeView: TTreeView): string; function Get_node_path(node: TTreeNode): string; function ExtractTreeView
File
Name(RootPath: string; TreeView: TTreeView): string; /// /// Node.Selected := true; Node.Focused := true; /// /// /// Node.Selected := true; Node.Focused := true; /// /// /// Node.Selected := true; Node.Focused := true; /// function Open
File
(Path: string; RichEdit: TRichEdit; TreeView: TTreeView) : Boolean; overload; function Open
File
(Path: string; Webbrowser: TWebbrowser; TreeView: TTreeView) : Boolean; overload; procedure GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; Include
File
s: Boolean); procedure DirToTreeView(Tree: TTreeView; Directory: string; Root: TTreeNode; Include
File
s: Boolean;
File
Ext: string); procedure QSetPerpoty(TreeView: TTreeView); function ItemExist(Text: string; TreeView: TTreeView): Boolean; function RemoveDirs(folderPath: string): Boolean; function __Rename
File
(OldName: string; Title: string): Boolean; function RenameFolder(
file
Path: string; Title: string): Boolean; var list: TStringList; implementation { // "D:\C++Builder学习大全中文版\index.htm" // "D:\C++Builder学习大全中文版\" // "index_
file
s" // "D:\C++Builder学习大全中文版\index_
file
s" var s, s1, s2: string; begin s := 'D:\C++Builder学习大全中文版\index.htm'; s1:=ExtractNewFolderPath(s,'_
file
s'); s2 := ExtractNewFolderPath(s, '_AttachMents'); Memo1.lines.Add(s); Memo1.Lines.Add(s1); Memo1.lines.Add(s2); end; } function ExtractNewFolderPath(
File
Name: string; NewText: string): string; var _
file
sFolder: string; // "D:\C++Builder学习大全中文版\" _
file
sFolderName: string; // "index_
file
s" _
file
sFolderPath: String; begin _
file
sFolder := Extract
File
Path(
File
Name); _
file
sFolderName := Change
File
Ext(Extract
File
Name(
File
Name), '') + NewText; _
file
sFolderPath := _
file
sFolder + _
file
sFolderName; Result := _
file
sFolderPath; end; { SaveTreeViewExplandState(TreeView1,'TreeView.txt'); } procedure SaveTreeViewExplandState(TreeView: TTreeView;
File
Name: string); var list: TStringList; i: Integer; begin list := TStringList.Create; With TreeView do begin for i := 0 to Items.Count - 1 do begin if Items.Item[i].Expanded then list.Add(IntToStr(i)); end; list.Add(IntToStr(Selected.AbsoluteIndex)); end; list.SaveTo
File
(
File
Name); list.free; end; { LoadTreeViewExplandState(TreeView1, 'abc.txt'); } procedure LoadTreeViewExplandState(TreeView: TTreeView;
File
Name: string); var list: TStringList; i: Integer; node: TTreeNode; begin list := TStringList.Create; with list do begin list.LoadFrom
File
(
File
Name); for i := 0 to Count - 2 do // 最后一行放的是最后选中的那个节点索引 begin TreeView.Items[StrToInt(list[i])].Expand(False); end; node := TreeView.Items[StrToInt(list[Count - 1])]; TreeView.Select(TreeView.Items[StrToInt(list[Count - 1])], []); // node.Selected := True; // node.Focused := True; TreeView.SetFocus; TreeView.Focused; free; end; end; { FUNCTION ulong ShowScrollBar(ulong hwnd,ulong wBar,ulong bShow) LIBRARY "user32.dll" constant long SB_HORZ = 0 constant long SB_VERT = 1 constant long SB_BOTH = 3 } procedure HideHideHorizontalScrollBar(TreeView: TTreeView); begin // no responed NEW FORM TEST // ShowScrollBar(TreeView.Handle,SB_HORZ,False); end; // procedure // begin // { 当拖拽的高度不够的时候自动滚动滚动条 } // with TreeView1 do // begin // if (Y < 15) then // SendMessage(Handle, WM_VSCROLL, SB_LINEUP, 0) // else if (Height - Y < 15) then // SendMessage(Handle, WM_VSCROLL, SB_LINEDOWN, 0); // end; // end; { 返回 附件文件夹 "D:\C++Builder学习大全中文版\
新建
文本文档.htm" D:\C++Builder学习大全中文版\
新建
文本文档_Attachments } function AttachmentsFolder(
File
Name: String): string; begin Result := Extract
File
Path(
File
Name) + Change
File
Ext(Extract
File
Name(
File
Name), '') + '_Attachments'; end; function AttachMentsExists(
File
Name: String): Boolean; var f: string; begin f := Extract
File
Path(
File
Name) + Change
File
Ext(Extract
File
Name(
File
Name), '') + '_Attachments'; Result := DirectoryExists(f); end; procedure EnumText(s: string; aItem: TTreeNode); var node: TTreeNode; str: string; begin node := aItem; while node nil do begin if s = '' then str := node.Text else str := s + '\' + node.Text; list.Add(str); /// ////////////////////////// if node.HasChildren then EnumText(str, node.getFirstChild); node := node.getNextSibling; end; end; function IsEmptyDir(sDir: String): Boolean; var sr: TSearchRec; begin Result := True; if Copy(sDir, Length(sDir) - 1, 1) '\' then sDir := sDir + '\'; if FindFirst(sDir + '*.*', faAny
File
, sr) = 0 then repeat if (sr.Name '.') and (sr.Name '..') then begin Result := False; break; end; until FindNext(sr) 0; FindClose(sr); end; { 是文件 夹的设置为1 是文件 的设置为 2 } procedure SetIcons(TreeView: TTreeView; list: TStringList); var i: Integer; begin with TreeView do begin for i := 0 to Items.Count - 1 do begin if DirectoryExists(list.Strings[i]) then begin Items[i].ImageIndex := 0; Items[i].SelectedIndex := 0; Items[i].StateIndex := 0; end; if
File
Exists(list.Strings[i]) then begin Items[i].ImageIndex := 1; Items[i].SelectedIndex := 1; Items[i].StateIndex := 1; end; if (AttachMentsExists(list.Strings[i])) then if not IsEmptyDir(AttachmentsFolder(list.Strings[i])) then begin // Form1.Memo1.LINES.Add( AttachmentsFolder(list.Strings[i])); Items[i].ImageIndex := 2; Items[i].SelectedIndex := 2; Items[i].StateIndex := 2; end; end; end; end; procedure QSetPerpoty(TreeView: TTreeView); begin with TreeView do begin // Align := alBottom; // Anchors := [akLeft, akTop, akBottom, akRight]; Items.Clear; // BorderStyle := bsNone; Cursor := crHandPoint; ReadOnly := True; ShowHint := True; RowSelect := True; ShowButtons := True; ShowRoot := True; ShowLines := False; SortType := stText; HideSelection := False; RightClickSelect := True; DragMode := dmAutomatic; // Color := RGB(238, 243, 246); end; end; { 实际重命名 C:\windows\test.txt C:\windows\csadsajas.txt Move
File
(PChar('C:\1.txt'),PChar('C:\ABC.txt')); if not __Rename
File
('C:\tree.txt','TreeView') then Application.MessageBox('重命名文件失败','重命名',MB_ICONERROR); } { 重命名文件 } function __Rename
File
(OldName: string; Title: string): Boolean; var NewName: string; begin NewName := Format('%s%s%s', [Extract
File
Path(OldName), Title, Extract
File
Ext(OldName)]); Result := Move
File
(PChar(OldName), PChar(NewName)); end; // 重命名文件夹 // RenameFolder('C:\1\','2'); // Move
File
('C:\1','C:\2'); // Move
File
('C:\1\','C:\2\'); function RenameFolder(
file
Path: string; Title: string): Boolean; var s, s1: string; begin //
file
Path:='C:\Windows\System32\'; // s = Extract
File
Dir(
file
path) = 'C:\Windows\System32' s := Extract
File
Dir(
file
Path); // s1 = Extract
File
Dir(s) = 'C:\Windows' // s1 ='C:\Windows' +'\'+ titles s1 := Extract
File
Dir(s) + '\' + Title; Result := Move
File
(PChar(s), PChar(s1)); end; { IOUtils } function RemoveDirs(folderPath: string): Boolean; begin Result := False; if TDirectory.IsEmpty(folderPath) then begin TDirectory.Delete(folderPath); Result := True; end else begin if Application.MessageBox('确定要删除这个文件夹吗? 删除后无法恢复!', '提示', MB_ICONQUESTION + MB_YESNO) = ID_YES then begin TDirectory.Delete(folderPath, True); Result := True; end; end; // if TDirectory.Exists(folderPath) then // begin // Application.MessageBox('删除文件失败'+#13#10+'文件正确被使用?','错误',MB_ICONERROR+MB_OK); // Result:=False; // end; end; { if not ItemExist('Edit1.Text',TreeView1) then TreeView1.Items.AddChild(Treeview1.Selected,'Edit1.Text'); } function ItemExist(Text: string; TreeView: TTreeView): Boolean; var i: Integer; begin Result := False; if (Trim(Text) '') then begin for i := 0 to TreeView.Items.Count - 1 do if Trim(Text) = Trim(TreeView.Items[i].Text) then begin Result := True; Exit; end; end; Result := False; end; // ------------------------------------------------------------------------------ { TreeView获得选中的完整路径 aaaa\ssss\bbbb } function ExtractNodeFullPath(TreeView: TTreeView): string; var Path: string; Parent: TTreeNode; // Node: TTreeNode; begin Path := TreeView.Selected.Text; Parent := TreeView.Selected.Parent; while Parent nil do begin Path := Parent.Text + '\' + Path; Parent := Parent.Parent; end; Result := Path; end; function Get_node_path(node: TTreeNode): string; var Path: string; TreeNode: TTreeNode; begin Path := node.Text; TreeNode := node.Parent; while TreeNode nil do begin Path := TreeNode.Text + '\' + Path; TreeNode := TreeNode.Parent; end; Result := Path; end; { 获得文件完整路径 C:\abc\int.
cpp
} function ExtractTreeView
File
Name(RootPath: string; TreeView: TTreeView): string; var
File
Name: string; begin Result := ''; if TreeView.Selected = nil then Exit;
File
Name := RootPath + ExtractNodeFullPath(TreeView); // 当前选中的文件名 if not
File
Exists(
File
Name) then Exit; Result :=
File
Name; end; { 用RICHEDIT打开TREEVIEW中的文件 } function Open
File
(Path: string; RichEdit: TRichEdit; TreeView: TTreeView) : Boolean; overload; var
File
Name: string; begin Result := False;
File
Name := ExtractTreeView
File
Name(Path, TreeView); if
File
Exists(
File
Name) then begin RichEdit.Lines.LoadFrom
File
(
File
Name); Result := True; end end; function Open
File
(Path: string; Webbrowser: TWebbrowser; TreeView: TTreeView) : Boolean; overload; var
File
Name: string; begin Result := False;
File
Name := ExtractTreeView
File
Name(Path, TreeView); if
File
Exists(
File
Name) then begin Webbrowser.Navigate(
File
Name); Result := True; end end; { 将1个目录里面所有的文件添加到TREEVIEW中 GetDirectories(TreeView1, 'D:\DATA', nil, True); } procedure GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; Include
File
s: Boolean); var SearchRec: TSearchRec; ItemTemp: TTreeNode; begin Tree.Items.BeginUpdate; if Directory[Length(Directory)] '\' then Directory := Directory + '\'; if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then begin repeat if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] '.') then begin if (SearchRec.Attr and faDirectory > 0) then Item := Tree.Items.AddChild(Item, SearchRec.Name); ItemTemp := Item.Parent; GetDirectories(Tree, Directory + SearchRec.Name, Item, Include
File
s); Item := ItemTemp; end else if Include
File
s then if SearchRec.Name[1] '.' then Tree.Items.AddChild(Item, SearchRec.Name); until FindNext(SearchRec) 0; FindClose(SearchRec); Tree.Items.EndUpdate; end; end; { 将1个目录里面所有的文件添加到TREEVIEW中 DirToTreeView(TreeView1,'D:\Data\',nil,True,'.
cpp
'); } procedure DirToTreeView(Tree: TTreeView; Directory: string; Root: TTreeNode; Include
File
s: Boolean;
File
Ext: string); var SearchRec: TSearchRec; Node1: TTreeNode; begin with Tree.Items do begin BeginUpdate; if Directory[Length(Directory)] '\' then Directory := Directory + '\'; if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then begin Application.ProcessMessages; repeat { 添加文件夹 } if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] '.') then begin if SameText(RightStr(SearchRec.Name, 12), '_AttachMents') then // 不添加 _AttachMents这个文件夹 Continue; if (SearchRec.Attr and faDirectory > 0) then Root := AddChild(Root, SearchRec.Name); Node1 := Root.Parent; DirToTreeView(Tree, Directory + SearchRec.Name, Root, Include
File
s,
File
Ext); Root := Node1; end else if Include
File
s then { 添加文件 } if SearchRec.Name[1] '.' then { .TXT .txt .TxT .tXT 为一样的 } if SameText(RightStr(SearchRec.Name, 4),
File
Ext) then { 只添加 .
CPP
格式文件 } AddChild(Root, SearchRec.Name); until FindNext(SearchRec) 0; FindClose(SearchRec) end; EndUpdate; end; end; end.
代码语法错误分析工具pclint8.0
代码静态分析工具PC-LINT安装配置 PC-Lint是C/C++软件代码静态分析工具,你可以把它看作是一种更加严格的编译器。它不仅可以检查出一般的语法错误,还可以检查出那些虽然符合语法要求但不易发现的潜在错误。 C语言的灵活性带来了代码效率的提升,但相应带来了代码编写的随意性,另外C编译器不进行强制类型检查,也带来了代码编写的隐患。PCLint识别并报告C语言中的编程陷阱和格式缺陷的发生。它进行程序的全局分析,能识别没有被适当检验的数组下标,报告未被初始化的变量,警告使用空指针,冗余的代码,等等。软件除错是软件项目开发成本和延误的主要因素。PClint能够帮你在程序动态测试之前发现编码错误。这样消除错误的成本更低。 使用PC-Lint在代码走读和单元测试之前进行检查,可以提前发现程序隐藏错误,提高代码质量,节省测试时间。并提供编码规则检查,规范软件人员的编码行为。 由于PC-LINT对于一般程序员来说可能比较陌生,有好多人安装了也不知道怎样配置和使用。 下面我就根据自己的安装和配置心得对PC-Lint的安装、配置及使用进行下详细说明.本人主要介绍了将PC-Lint集成到VC++6.0和SourceInsight的方法和步骤。 (一)Windows下C/C++开发工具中,VC6使用较为普遍,因此这里先讲下VC6.0环境中集成pclint的步骤. 首先, 当然要下载软件,正版软件要200多$呢,买不起!所以只好网上找免费的拉。从http://www.61ic.com/down/othe/pclint.rar处可以下载到一个8.0版本的pclint. 1.将pclint.rar解压至c:\, 这样lint文件就位与c:\pclint(安装目录)下了。 2.将c:\pclint\lnt 下的3个文件lib-w32.lnt,env-vc6.lnt,co-msc60.lnt拷贝至c:\pclint下, 再在安装目录下创建std.lnt和options.lnt两个文件,其中std.lnt的内容如下 // contents of std.lnt c:\pclint\co-msc60.lnt c:\pclint\lib-w32.lnt c:\pclint\options.lnt -si4 -sp4 -i"D:\Program
File
s;D:\Program
File
s\Microsoft Visual Studio\VC98\Include" //end 其中-i后面的路径名为VC的安装路径和VC Include 文件路径,根据自己的修改便可。 options.lnt 内容可为空,为定制内容,以后需要时再添加。 准备工作做完了,下一步就是要将pclint集成到VC6中去,先配置lint使之能对单个C或C++文件进行检查。 1.打开VC6,tools--->customize-->tools
新建
一个名为pclint的项,在下面填入 command: C:\pclint\lint-nt.exe arguments: -u c:\pclint\std.lnt c:\pclint\env-vc6.lnt "$(
File
Path)" Use Output Window 打上勾 close 完成。 这个在你VC窗口tools菜单下应该多了一个pclint选项,可以用它来运行lint程序,对你的c/c++代码进行静态检查了。 现在就可以用个小程序测试一下pclint了 //test1.
cpp
#include class X { int *p; public: X() { p = new int[20]; } void init() { memset( p, 20, 'a' ); } ~X() { delete p; } }; 编译这个文件,看下你的编译器给你多少警告,再运行下lint, 可以自己对比一下。 我的机器上,VC产生0 errors 0 warnings, 而lint程序产生了如下8条警告信息,有些还是很有用处的提示,这里就不一一分析了. test.
cpp
(12): error 783: (Info -- Line does not end with new-line) test.
cpp
(7): error 1732: (Info -- new in constructor for class 'X' which has no assignment operator) test.
cpp
(7): error 1733: (Info -- new in constructor for class 'X' which has no copy constru
cpp
check静态代码检查工具使用教程
cpp
check 进行代码检查的方法
Jenkins中使用
cpp
check进行C代码检查
2019独角兽企业重金招聘Python工程师标准>>> ...
Cpp
Check静态代码检查工具教程【Windows和Linux端】
cpp
ceck 是一个 C/C++ 代码分析工具。与 C/C++ 编译器和许多其他分析工具不同,它不检测语法错误。
cpp
check 仅检测编译器通常无法检测到的错误类型。目标是没有误报。检查结果error:出现的错误warning:为了预防bug防御性编程建议信息越style:编码格式问题(没有使用的函数、多余的代码等)portablity:移植性警告。该部分如果移植到其他平台上,可能出现兼容性问题performance:建议优化该部分代码的性能。
C++ Builder
13,824
社区成员
102,679
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章