当前位置: 首页 > news >正文

如何用两台电脑做服务器建网站seo图片优化的方法

如何用两台电脑做服务器建网站,seo图片优化的方法,软件开发项目报价模板,上线了怎么做网站14.3.2 特定类约束 ​ 如果您的泛型类需要使用某个特定子集的类&#xff08;特定层次结构&#xff09;&#xff0c;则可能需要根据给定基类指定约束。 ​ 例如&#xff0c;如果您声明&#xff1a; typeTCompClass<T: TComponent> class​ 则此泛型类的实例仅适用于组…
14.3.2 特定类约束

​ 如果您的泛型类需要使用某个特定子集的类(特定层次结构),则可能需要根据给定基类指定约束。

​ 例如,如果您声明:

typeTCompClass<T: TComponent> = class

​ 则此泛型类的实例仅适用于组件类,即任何TComponent后代类。这使您拥有一个非常特定的泛型类型(是的,听起来很奇怪,但这确实是它的实际情况),并且编译器将允许您在处理泛型类型时使用TComponent类的所有方法。

​ 如果这看起来非常强大,那么请三思。如果你考虑一下利用继承和类型兼容规则可以实现的功能,也许你可以使用传统的面向对象技术来解决同样的问题,而不必使用泛型类。我并不是说特定的类约束从来都没有用,但它肯定没有更高级别的类约束或(我觉得非常有趣的)基于接口的约束强大。

14.3.3 接口约束

​ 一般来说,更灵活的做法是只接受实现特定接口的类作为类型参数,而不是将一个泛型类约束为一个给定的类。这样就可以在泛型的实例上调用接口。在 C# 语言中,将接口约束用于泛型也很常见。让我先展示给你一个示例(来自IntfConstraint示例)。首先,我们需要声明一个接口:

typeIGetValue = interface['{60700EC4-2CDA-4CD1-A1A2-07973D9D2444}']function GetValue: Integer;procedure SetValue(Value: Integer);property Value: Integer read GetValue write SetValue;end;

​ 接下来,我们可以定义一个实现它的类:

typeTGetValue = class(TNoRefCountObject, IGetValue)privateFValue: Integer;publicconstructor Create(Value: Integer = 0);function GetValue: Integer;procedure SetValue(Value: Integer);end;

​ 在限制为实现特定接口的类型的泛型类的定义中,事情开始变得有趣:

typeTInftClass<T: IGetValue> = classprivateFVal1, FVal2: T; // Or IGetValuepublicprocedure Set1(Val: T);procedure Set2(Val: T);function GetMin: Integer;function GetAverage: Integer;procedure IncreaseByTen;end;

​ 请注意,在这个类的泛型方法的代码中,我们可以编写:

function TInftClass<T>.GetMin: Integer;
beginResult := Min(FVal1.GetValue, FVal2.GetValue);
end;procedure TInftClass<T>.IncreaseByTen;
beginFVal1.SetValue(FVal1.GetValue + 10);FVal2.Value := FVal2.Value + 10;
end;

​ 有了所有这些定义,我们现在可以按以下方式使用泛型类:

procedure TFormIntfConstraint.BtnValueClick(Sender: TObject);
varIClass: TInftClass<TGetValue>;
beginIClass := TInftClass<TGetValue>.Create;tryIClass.Set1(TGetValue.Create(5));IClass.Set2(TGetValue.Create(25));Show('Average: ' + IntToStr(IClass.GetAverage));IClass.IncreaseByTen;Show('Min: ' + IntToStr(IClass.GetMin));finallyIClass.FVal1.Free;IClass.FVal2.Free;IClass.Free;end;
end;

​ 为了展示这个泛型类的灵活性,我为接口创建了另一个完全不同的实现方法:

type
TButtonValue = class(TButton, IGetValue)
publicfunction GetValue: Integer;procedure SetValue(Value: Integer);class function MakeTButtonValue(Owner: TComponent; Parent: TWinControl): TButtonValue;
end;function TButtonValue.GetValue: Integer;
beginResult := Left; // use base class property
end;procedure TButtonValue.SetValue(Value: Integer);
beginLeft := Value; // use base class property
end;

​ 该类函数(此处未显示)在父控件中创建了一个随机位置的按钮。位置创建一个按钮,并在以下示例代码中使用:

procedure TFormIntfConstraint.BtnValueButtonClick(Sender: TObject);
varIClass: TInftClass<TButtonValue>;
beginIClass := TInftClass<TButtonValue>.Create;tryIClass.Set1(TButtonValue.MakeTButtonValue(Self, ScrollBox1));IClass.Set2(TButtonValue.MakeTButtonValue(Self, ScrollBox1));Show('Average: ' + IntToStr(IClass.GetAverage));Show('Min: ' + IntToStr(IClass.GetMin));IClass.IncreaseByTen;Show('New Average: ' + IntToStr(IClass.GetAverage));finallyIClass.Free;end;
end;
http://www.hkea.cn/news/828700/

相关文章:

  • 做网站的上海公司有哪些情感链接
  • 梧州做网站建设数字营销公司
  • 加强新闻网站建设建议seo高手培训
  • 安丘网站建设制作怎样制作网页设计
  • 食品网站建设优化案例热门职业培训班
  • 龙华新区做网站大地seo视频
  • 网站彩票投注员做啥的真正免费的网站建站平台运营
  • wordpress 中文注册鸡西seo
  • 佛山企业如何建网站seo的内容怎么优化
  • 在什么网站上做自媒体windows优化大师是自带的吗
  • 装修公司的网站怎么做第三方营销平台有哪些
  • 百度公司做网站吗手机网页链接制作
  • 武汉移动网站制作今天新闻最新消息
  • 酒泉建设厅网站百度seo刷排名软件
  • 天津个人网站建设yandex引擎
  • 网站改版建设 有哪些内容网络营销策划方案怎么做
  • 网站建设拾金手指下拉seo的实现方式
  • 北京宣传片湖南seo优化哪家好
  • 下载app 的网站 如何做黑帽seo排名技术
  • 个人是否做众筹网站哪里可以免费推广广告
  • 外贸网站该怎么做青岛百度推广优化怎么做的
  • 网站建设中 网页代码优化关键词排名公司
  • 网站标题优化怎么做泉州百度首页优化
  • 学习网站建设的是什么专业优化网站排名公司
  • 固定ip做网站西安网站建设推广
  • 做响应式网站好不好软文发布门户网站
  • 重庆做网站建设的公司哪家好最基本的网站设计
  • 长春网站制作wang网站营销软文
  • discuz 网站搬家市场营销的策划方案
  • 做婚礼网站的公司简介seo网站关键词优化软件