平台移植,求各位帮忙看看,帮我把下面的代码改称vc的格式,在下多谢了!!!

wishczhe 2005-12-19 09:05:24
TKddRec和TtestRec为自定义结构体类型

procedure TForm1.Button5Click(Sender: TObject);
var
i,j,k,m,intisoland,intk,intRecCount:integer;
s,sNeighbors,sAntiNeighbors:TStringList; //s:所有记录的id号,sNeighbors:该点最邻近点集合,sAntiNeighbors:以该点为最邻近点集合
inttop,intvalue,intbuttom:real;
d,dis:real; //d:给定域值 dis:两条记录间的距离
dsthostcount,arrdsthostcount:TKddRec;
f:TextFile;
strText,strid,strText1,strIntrusion:String; //strText1:每个聚类中所含有的记录的id号
disd0,disd1,disd2:Real; //相同字段相减
onePoint:^TtestRec; //一条记录的五元集
recStack:TStack;
intID,intNeiID,intAntiNeiID,Index,intCount,intsum:Integer;
onerecord:array[0..1000]of TKddRec; //记录数组
testRecord:array[0..1000]of TtestRec; //每个记录的最近邻相关信息
begin
try
//取得所有记录的id号
s:=TStringList.Create;
d:=strtofloat(edit2.Text);
intisoland:=0;
adosel.Close;
adosel.SQL.Clear;
adosel.SQL.Text:='select id from '+Trim(edit1.Text);
adosel.Open;
intRecCount:=adosel.RecordCount;
for i:=0 to intRecCount-1 do
begin
testRecord[i].Dir:=adosel.Fields.Fields[0].AsInteger;
if i<>adosel.RecordCount-1 then
strid:=strid+adosel.Fields.Fields[0].AsString+','
else
strid:=strid+adosel.Fields.Fields[0].AsString;
adosel.Next;
end;
s.DelimitedText:=strid;
s.Delimiter:=',';
adosel.close;
adosel.SQL.Clear;
adosel.SQL.Text:='select * from '+Trim(edit1.Text);
adosel.Open;
adosel.First;
for i:=0 to adosel.RecordCount-1 do
begin
intvalue:=adosel.FieldByName('dst_host_count').AsFloat;
inttop:=abs(intvalue)+d; //最大值
intbuttom:=abs(intvalue)-d;//最小值
dsthostcount.rdid:=adosel.FieldByName('id').AsInteger; //0
dsthostcount.element_con[0]:=adosel.FieldByName('duration').AsFloat;
dsthostcount.element_con[1]:=adosel.FieldByName('count').AsFloat;
dsthostcount.element_con[2]:=adosel.FieldByName('srv_count').AsFloat;
dsthostcount.element_sym[0]:=adosel.FieldByName('land').AsInteger;
dsthostcount.element_sym[1]:=adosel.FieldByName('logged_in').AsInteger;
//dsthostcount.element_sym[2]:=adosel.FieldByName('root_shell').AsInteger;
dsthostcount.element_sym[3]:=adosel.FieldByName('is_host_login').AsInteger;
dsthostcount.element_sym[4]:=adosel.FieldByName('is_guest_login').AsInteger;
dsthostcount.ele_proto:=adosel.FieldByName('protocol_type').AsString;
dsthostcount.ele_serv:=adosel.FieldByName('service').AsString;
dsthostcount.ele_flag:=adosel.FieldByName('flag').AsString;
adoavg.Close;
adoavg.SQL.Clear;
adoavg.SQL.Text:='select * from '+Trim(edit1.Text)+' where dst_host_count>='''+floattostr(intbuttom)+''' and dst_host_count<='''+floattostr(abs(inttop))+'''';
//showmessage(adoavg.SQL.Text);
adoavg.Open;
adoavg.First;
for j:=0 to adoavg.RecordCount-1 do
begin
arrdsthostcount.rdid:=adoavg.FieldByName('id').AsInteger;
arrdsthostcount.element_con[0]:=adoavg.FieldByName('duration').AsFloat;
arrdsthostcount.element_con[1]:=adoavg.FieldByName('count').AsFloat;
arrdsthostcount.element_con[2]:=adoavg.FieldByName('srv_count').AsFloat;
arrdsthostcount.element_sym[0]:=adoavg.FieldByName('land').AsInteger;
arrdsthostcount.element_sym[1]:=adoavg.FieldByName('logged_in').AsInteger;
//arrdsthostcount.element_sym[2]:=adoavg.FieldByName('root_shell').AsInteger;
arrdsthostcount.element_sym[3]:=adoavg.FieldByName('is_host_login').AsInteger;
arrdsthostcount.element_sym[4]:=adoavg.FieldByName('is_guest_login').AsInteger;
arrdsthostcount.ele_proto:=adoavg.FieldByName('protocol_type').AsString;
arrdsthostcount.ele_serv:=adoavg.FieldByName('service').AsString;
arrdsthostcount.ele_flag:=adoavg.FieldByName('flag').AsString;
if arrdsthostcount.rdid<>dsthostcount.rdid then
begin
disd0:=abs(dsthostcount.element_con[0]-arrdsthostcount.element_con[0]);
disd1:=abs(dsthostcount.element_con[1]-arrdsthostcount.element_con[1]);
disd2:=abs(dsthostcount.element_con[2]-arrdsthostcount.element_con[2]);

if (disd0<=d) and (disd1<=d) and (disd2<=d) then
begin
//算距离
for k:=0 to 19 do
begin
dis:=dis+(dsthostcount.element_con[k]-arrdsthostcount.element_con[k])*(dsthostcount.element_con[k]-arrdsthostcount.element_con[k]);
end;
if arrdsthostcount.ele_proto<>dsthostcount.ele_proto then
dis:=dis+1/9;
if arrdsthostcount.ele_serv<>dsthostcount.ele_serv then
dis:=dis+(1/14)*(1/14);
if arrdsthostcount.ele_flag<>dsthostcount.ele_flag then
dis:=dis+1/9;
for k:=1 to 4 do
begin
if arrdsthostcount.element_sym[k]<>dsthostcount.element_sym[k] then
dis:=dis+1/4;
end;
dis:=Sqrt(dis);
//记录信息
if dis<=d then
begin
for m:=0 to adosel.RecordCount-1 do
begin
if testRecord[m].Dir=dsthostcount.rdid then
begin //判断是否为最短距离
if (testRecord[m].Distance>dis)or(testRecord[m].Distance=0) then
testRecord[m].Distance:=dis;
if testRecord[m].Neighbors<>'' then
testRecord[m].Neighbors:=testRecord[m].Neighbors+','+inttostr(arrdsthostcount.rdid)
else
testRecord[m].Neighbors:=inttostr(arrdsthostcount.rdid);
end;
if testRecord[m].Dir=arrdsthostcount.rdid then
begin
if testRecord[m].AntiNeighbors<>'' then
testRecord[m].AntiNeighbors:=testRecord[m].AntiNeighbors+','+inttostr(dsthostcount.rdid)
else
testRecord[m].AntiNeighbors:=inttostr(dsthostcount.rdid);
end;
end;
end;
end;
end;
adoavg.Next;
end;
adosel.Next;
end;
except
on E: Exception do showmessage(E.Message);
end;
end;
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingpiao 2005-12-19
  • 打赏
  • 举报
回复
真长
begin =>{
end => }
:= => =
then 去掉
except =》catch(...)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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