不同函数间如何调用变量?

challengerzm 2003-08-21 04:41:56
写文件日志,文件名是MakeFileName()函数产生的
void __fastcall TForm1::mysyslogDataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{


//Use ascii file record the log,define the log's file;

FILE *fLog;
char *sBuf;
char *writefile;

writefile=filename.c_str();
if ( (fLog = fopen(writefile, "at")) == NULL )
{
ShowMessage("写入文件出错!");

}
else
{
int j;
char Buff[1024];
mysyslog->ReadBuffer(Buff,1024,j);

Buff[j]=0;
sMessage = Buff ;
sMessage =sMessage + "\n" ;
sBuf = sMessage.c_str();
fwrite(sBuf, StrLen(sBuf), 1, fLog);
//fclose(fLog);
}


}


检测文件大小,到达一定尺寸关闭文件,产生新文件
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
HFILE hFile;
char *str;

str=filename.c_str();
hFile=_lopen(str,OF_READ);
filesize=GetFileSize((HANDLE*)hFile,0); //size is Byte.
//filesize=filesize/1024; //size is kB
filesize=filesize/1048576; //size is MB.
if (filesize >= newfilesize)
{

fclose(fLog);//关闭文件

MakeFileName();//新建文件名
};

}

fclose(fLog);编译时出错提示:
[C++ Error] Unit1.cpp(181): E2451 Undefined symbol 'fLog'
希望能得到老手的指教,如何实现此功能。
...全文
115 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
challengerzm 2003-08-28
  • 打赏
  • 举报
回复
有高手可以指点我么?
challengerzm 2003-08-27
  • 打赏
  • 举报
回复
剪切的文件是该程序退出前产生过的文件,非当前写入的文件。再拜各位高手指点。
challengerzm 2003-08-22
  • 打赏
  • 举报
回复
#include "stdio.h"
后编译通过,但是程序产生的日志,在剪切时仍提示文件正在使用,退出程序,就可以剪切了。是什么原因呢?
dongyangzong 2003-08-22
  • 打赏
  • 举报
回复
文件关闭之前,就会提示文件正在使用.退出程序时,文件自动关闭了.
你的定时程序中,只有文件大小到一定程度才关闭文件.
challengerzm 2003-08-21
  • 打赏
  • 举报
回复
不报错了,我看看是否起作用。
#include "stdio.h"
我已经加在.cpp文件里,和加在.h文件有什么区别呢?
ccrun.com 2003-08-21
  • 打赏
  • 举报
回复
#include "stdio.h"
challengerzm 2003-08-21
  • 打赏
  • 举报
回复
在函数里声明没有问题
FILE *fLog;
char *sBuf;
char *writefile;
在.h文件声明就有出错提示:
[C++ Error] Unit1.h(92): E2303 Type name expected
[C++ Error] Unit1.h(92): E2139 Declaration missing ;
[C++ Error] Unit1.cpp(109): E2451 Undefined symbol 'fLog'
[C++ Error] Unit1.cpp(181): E2451 Undefined symbol 'fLog'
是否需要包含什么文件呢?
challengerzm 2003-08-21
  • 打赏
  • 举报
回复
FILE *fLog;
定义为全局,这一个变量报错
ccrun.com 2003-08-21
  • 打赏
  • 举报
回复
定义成全局。

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧